SELECT cast(id as varchar(8)) new_id FROM tourol_Atractions where tcid>0 order by new_id SELECT top 1 new_id = stuff ((SELECT ',' + cast(id as varchar(8)) FROM tourol_Atractions WHERE tcid>0 FOR xml path('')), 1, 1, '') FROM [tourol_Atractions] wher…
今天工作时遇见一个数据查询分组问题,就是将分组后同一组数据某一列合并为一行,因为之前很少用到,这次工作中刚好有用到,所以手痒难耐,将它记录下来. 查询sql如下: select t.province_code provinceCode, listagg(t.city_code || '-' || t.city_name, ',') within group(order by t.city_code) city from city t group by t.province_code; 查询效果如…