admin管理员组文章数量:1568346
mysql及oracle中的group_contact小结
今天有个朋友问,如下的合拼,如何写法,分别在MYSQL和ORACLE:
数据库的结构如下:
no item
01 AA
01 BB
02 CC
02 DD
02 EE
03 FF
04 GG
04 HH
希望将no相同的列整合为一条记录如下
no items
01 AA,BB
02 CC,DD,EE
03 FF
04 GG,HH
MYSQL中,直接有group_contact函数了,如下:
select id,group_contact(items) from TABLE group by id
而oracle中,对应的有wm_contact,摘抄例子如下:
select id,wmsys.wm_concat(items) name from table
group by id;
再看SQL SERVER 2005:
--SQL2005中的方法
create table tb(id int, value varchar(10)) insert into tb values(1, 'aa') insert into tb values(1, 'bb') insert into tb values(2, 'aaa') insert into tb values(2, 'bbb') insert into tb values(2, 'ccc') go select id, [values]=stuff((select ','+[value] from tb t where id=tb.id for xml path('')), 1, 1, '') from tb group by id /* id values ----------- -------------------- 1 aa,bb 2 aaa,bbb,ccc
1
createtabletb(idint,valuevarchar(10))insertintotbvalues(1,'aa')insertintotbvalues(1,'bb')insertintotbvalues(2,'aaa')insertintotbvalues(2,'bbb')insertintotbvalues(2,'ccc')goselectid,[values]=stuff((select','+[value]fromtbtwhereid=tb.idforxmlpath('')),1,1,'')fromtbgroupbyid/*idvalues-------------------------------1aa,bb2aaa,bbb,ccc
欢迎大家阅读《mysql及oracle中的group_contact总结》,跪求各位点评,by 搞代码
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~
本文标签: ContactmysqlgroupmysqlgroupcontactORACLE
版权声明:本文标题:mysql contact group_mysql及oracle中的group_contact总结 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1726639996a1079536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论