您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 丽江分类信息网,免费分类信息发布

用SQL得到全排列

2026/4/10 17:23:13发布10次查看
在表elements中存放了7个数,要得到这些数的全排列。 无 create table elements( i int not null primary key)goinsert into elementsvalues (1),(2),(3),(4),(5),(6),(7); with elementswithweight as( select i, power(2,(i-1)) as wgt from elements)selec
在表elements中存放了7个数,要得到这些数的全排列。 create table elements( i int not null primary key)goinsert into elementsvalues (1),(2),(3),(4),(5),(6),(7);
with elementswithweight as( select i, power(2,(i-1)) as wgt from elements)select e1.i, e2.i, e3.i, e4.i, e5.i, e6.i, e7.ifrom elementswithweight as e1, elementswithweight as e2, elementswithweight as e3, elementswithweight as e4, elementswithweight as e5, elementswithweight as e6, elementswithweight as e7where (e1.wgt + e2.wgt + e3.wgt + e4.wgt + e5.wgt + e6.wgt + e7.wgt) = 127
create table users (name char(2),value char(1),id number);insert into users values('甲','a',1);insert into users values('乙','b',2);insert into users values('丙','c',3);insert into users values('丁','d',4);commit;
select o.p as 排列 from (select replace (sys_connect_by_path( value, ',' ) , ',' ) p from users connect by nocycle value != prior value) o where length(o.p) =2;
select o.p as 排列 from (select replace (sys_connect_by_path( value, ',' ) , ',' ) p from users connect by nocycle value != prior value) o where length(o.p) =3;
select o.p as 排列 from (select replace (sys_connect_by_path( value, ',' ) , ',' ) p from users connect by nocycle value != prior value) o where length(o.p) =4;
丽江分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product