用sql语句实现在同一张表中找到1个字段相同,另1个字段不同的记录

问题补充:
比如表A中
字段1 字段2
2 43
3 65
2 68
1 92
2 55
1 100
用sql语句实现查询,查询出表
1 92、100
2 43、68、55
3 65
这样结果

如果是sql server 2005以下,可以用如下方式来实现
select t.col1,
stuff((select '、'+ convert(varchar(10),t1.col2)
from A t1 where t1.col1= t.col1 for xml path('')),1,1,'') as col2
from A t
group by t.col1
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-12-29
select 字段1, 字段2 from 表A group by 字段1
大家正在搜