我知道
- MySQL的合并场的方式:
CONCAT()
- 甲骨文:
CONCAT()
,||
- SQL Server:`+
但是... 我想合并AFTER查询,这有可能吗?
我知道
CONCAT()
CONCAT()
,||
但是... 我想合并AFTER查询,这有可能吗?
在这里你去:
MySQL的使用group_concat
:
select a.name,
a.opcode,
group_concat(month order by b.pk separator ', ') as months
from tablea a
join tableb b on a.opcode = b.opcode
group by a.name, a.opcode;
甲骨文使用listagg
:
select a.name,
a.opcode,
listagg(month,', ') within group (order by b.pk) as months
from tablea a
join tableb b on a.opcode = b.opcode
group by a.name, a.opcode;
SQL服务器使用for xml path
和stuff
:
select a.*,
stuff((
select ', ' + month from tableb b
where a.opcode = b.opcode
order by pk
for xml path(''), type
).value('(./text())[1]', 'varchar(max)')
, 1, 2, '') as months
from tablea a;
哪个目标数据库系统? – Lucero
您是否真的需要针对所有3种不同数据库产品的解决方案? –
SQL Server:http://stackoverflow.com/questions/1874966/concatenate-row-values-t-sql http://stackoverflow.com/questions/13639262/optimal-way-to-concatenate-aggregate-strings和其他... – Lucero