【发布时间】:2013-08-22 15:56:57
【问题描述】:
我有一张桌子:
col1 col2 ... Plastname Pfirstname Clastname Cfirstname
1 abc Smith John Robinson Bob
2 xyz Smith John Jones Michael
3 bda Robinson Bob Smith John
我想要的是一个不同名称的列表,例如:
col1
Smith, John
Robinson, Bob
Jones, Michael
我已经尝试过联合做:
select distinct Plastname + ', ' + Pfirstname as name from table
union
select distinct Clastname + ', ' + Cfirstname as name from table
但这并没有给我 clastname 和 cfirstname 的。
我也尝试过使用 distinct 和 group by 的各种尝试,但没有任何效果。
非常感谢任何建议或指导!
【问题讨论】:
-
什么平台? PostgreSQL、SQL Server、MySQL、Oracle?
-
sql-server,谢谢。更新的问题。
标签: sql sql-server group-by distinct