oracle 结果集排列组合解决方案
发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
oracle 结果集排列组合
有这样一个需求,原始数据为:
NAME GROUP
n1 null
n2 g1
n3 g1
n4 g2
n5 g2
需求,将名称按组进行排列组合,中间用:分隔,要求结果为
RESULT
n1:n2:n4
n1:n2:n5
n1:n3:n4
n1:n3:n5
也就是,每组最多有两个,每多一组,最后的结果集数量翻倍。求高手指点该怎么做,要用sql实现
------解决方案--------------------
没看懂,如果再多个g3会怎样
------解决方案--------------------
想了半天,能想出来的只有通过过程。
更好的思路请看楼下讲解。
------解决方案--------------------
这个题目还是有点难度的,你可以去itpub问问。。
------解决方案--------------------
http://www.itpub.net/thread-763065-1-1.html
看看这个:
SQL>
SQL> select replace (a.combo, '#') as "组合"
2 from
3 (select id,sys_connect_by_path (value, '#')
------解决方案--------------------
'#' combo
4 from (select 1 as id,value,1 as ctrl from users)
5 connect by prior id = id and value > prior value ) a,
6 (select 1 as id,value,1 as ctrl from users) b
7 where b.id = a.id and instr (a.combo, '#'
------解决方案--------------------
b.value
------解决方案--------------------
'#') > 0
8 group by a.id, a.combo
9 having sum (b.ctrl) = 3;
组合
--------------------------------------------------------------------------------
acd
abc
abd
bcd
------解决方案--------------------
冲你这句谢谢,研究了下。很繁琐的实现方式
select * from (
select case when b ='g2' then (
select g from
(
select g,rownum from (select case when b ='g1' then (select a from bb where b is null)
------解决方案--------------------
':'
------解决方案--------------------
a end g from bb) f
where g is not null
) g where rownum=1)
------解决方案--------------------
':'
------解决方案--------------------
a end ff
from bb
union
select case when b ='g2' then (
select g from
(
select g,rownum dd from (select case when b ='g1' then (select a from bb where b is null)
------解决方案--------------------
':'
------解决方案--------------------
a end g from bb) f
where g is not null
) g where dd=2)
------解决方案--------------------
':'
------解决方案--------------------
a end ff
from bb) ggg where ff is not null
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
创建同义词报ORA-00955
各位大神,我创建公有同义词,怎么会报ORA-00955错?很多人遇到建立私有同义词有这个错,我怎么建立公有同义词也...
-
impdp导入为什么索引会占的非常大。
本帖最后由 xixi_168 于 2014-07-19 23:10:47 编辑
在做数据...
-
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
测试没有成功。
ORA-12514: TNS: 监听程序当前无法识别连接描述...
-
oracle神牛进!!!
1、如何用sql查出oracle自带的所有函数?
2、给定ascii码,如何用sql查出对应的字符?
3、为什么在java中和在oracl...
-
oracle的cmd执行一个.sql文件,遇到异常时退出而不是继续执行
假设有一个1.sql文件,内容是
Declare
X varchar2(20);
Begin
Sc...
-
oracle查看某一条记录中为空的字段总数
oralce中,某一条记录中怎么得到这条记录中字段值为空的总数呢?(不为空的总数也可)
比如:id a1...
-
三台ORACLE通信,DBLINK
三台ORACLE服务器,A、B、C,其中A和B在同一个内网,B为双网卡可以连接外网,C为外网ORACLE。现在在B上已经建立DBL...
-
OracleOraDb10g_home1TNSListener无法启动
OracleOraDb10g_home1TNSListener无法启动,每次启动都提示:“在本地计算机无法启动Ora...
-
虚拟机安装RAC,网卡可以用NAT方式连接吗?
大家好:
我看教程上设的,安装配置RAC,配置虚拟机的两块网卡,第一块网卡(eth0,配置公用I...
-
求解oracle监听服务名问题
最近在做服务器的双机热备时,发现两边的监听服务名不一致,一个是OracleOraDb11g_home1TNSListen...