度量快速开发平台-专业、快速的软件定制快开平台

标题: 有ABCD四个字符。用SQL写出它的全排列 [打印本页]

作者: 张兴康    时间: 2020-4-16 18:24
标题: 有ABCD四个字符。用SQL写出它的全排列
方法一:
  1. with t as
  2. (select 'A' c1
  3.     from dual
  4.   union all
  5.   select 'B'
  6.     from dual
  7.   union all
  8.   select 'C'
  9.     from dual
  10.   union all
  11.   select 'D'
  12.     from dual)
  13. select substr(sys_connect_by_path(c1, ','), 2)
  14.   from t
  15. where level = 4
  16. connect by nocycle prior c1 != c1;
复制代码
方法二:
  1. WITH tmp AS
  2. (select 'A' as word
  3.     from dual
  4.   union all
  5.   select 'B'
  6.     from dual
  7.   union all
  8.   select 'C'
  9.     from dual
  10.   union all
  11.   select 'D'
  12.     from dual)
  13. select a.word, b.word, c.word, d.word
  14.   from tmp a, tmp b, tmp c, tmp d
  15. where a.word <> b.word
  16.    and a.word <> c.word
  17.    and a.word <> d.word
  18.    and b.word <> c.word
  19.    and b.word <> d.word
  20.    and c.word <> d.word
  21. order by 1, 2, 3, 4;
复制代码





作者: 万望    时间: 2020-4-17 05:08
lz每次发的都是好东西啊,能给我介绍哈啥子是全排列吗?
作者: 张兴康    时间: 2020-4-17 14:21
万望 发表于 2016-5-17 05:08
lz每次发的都是好东西啊,能给我介绍哈啥子是全排列吗?

a、b、c、d
a、b、d、c
。。。。。。
作者: 陈晓龙    时间: 2020-4-17 16:34
sql 真强大!
作者: 张兴康    时间: 2020-4-18 14:10
陈晓龙 发表于 2016-5-17 16:34
sql 真强大!

一直很强大
作者: 陈晓龙    时间: 2020-4-18 14:32
张兴康 发表于 2016-5-18 14:10
一直很强大


作者: 张兴康    时间: 2020-4-19 14:05
陈晓龙 发表于 2016-5-18 14:32


作者: 陈晓龙    时间: 2020-4-19 15:22
张兴康 发表于 2016-5-19 14:05


作者: 张兴康    时间: 2020-4-20 14:14
陈晓龙 发表于 2016-5-19 15:22


作者: 陈晓龙    时间: 2020-4-20 16:42
张兴康 发表于 2016-5-20 14:14

这是猪么!
作者: 张兴康    时间: 2020-4-23 13:40
陈晓龙 发表于 2016-5-20 16:42
这是猪么!

还是流鼻涕的
╭︿︿︿╮
{/ o  o /}  
( (oo) )   
  ︶︶︶




欢迎光临 度量快速开发平台-专业、快速的软件定制快开平台 (http://plat.delit.cn/) Powered by Discuz! X3.2