oracle数据库中在n个字段值相同时给另一字段值合并用逗号隔开

假设表中有以下字段,舱位信息表(cabin_info):

id         main_cabin       cabin_code        mileage_percentage

1          Y                           A                           1%

2          Y                           B                           1%

即如果main_cabin和mileage_percentage的值相同,就让cabin_code显示为A,B

sql语句应为:

select  t1.id,

case then

  count(t1.main_cabin)>1

then

  wmsys.wm_concat(t1.cabin_code)

else

  wmsys.wm_concat(t1.cabin_code)

case end,

t1.mileage_percentage

from  cabin_info  t1 group by  t1.id,t1.mileage_percentage;

你可能感兴趣的:(oracle)