oracle数据库查询
我在数据库中创建一张关联表,语句如下
create table T_CMS_COPYRIGHT_SD_COPYRIGHT
(
SDID NUMBER(20) NOT NULL,
COPYRIGHTID NUMBER(20) NOT NULL
)
向表中插入两条数据
insert into T_CMS_COPYRIGHT_SD_COPYRIGHT values('1','2312');
insert into T_CMS_COPYRIGHT_SD_COPYRIGHT values('1','22312');
我想通过一个条件 SDID 来获取COPYRIGHTID ,但是SIID对应多条记录
查询出就是多个,有没法办法将这些结果都查询到一个结果集,就是一条记录中
请问人知道如何写么? 谢谢
答案:很简单
select SDID,wm_concat(COPYRIGHTID) COPYRIGHTID from _CMS_COPYRIGHT_SD_COPYRIGHT group by SDID
其他:select SDID , max(substr(sys_connect_by_path(COPYRIGHTID, '/'),2)) str
from (SELECT SDID , COPYRIGHTID ,
row_number() OVER(PARTITION BY SDID ORDER BY SDID) RN
FROM T_CMS_COPYRIGHT_SD_COPYRIGHT
WHERE SDID='参数') t
start with rn = 1
connect by rn = prior rn + 1 and SDID = prior SDID
group by SDID
上一个:oracle 默认表空间是什么
下一个:在oracle中,怎么把新建的表空间给已经创建好的用户