说我有一张这样的表:
ID Description
1 A popular place to eat!
1 A popular place to eat!!
1 A popular place to eat!!!
2 Lets go!
2 Everyone, Lets go!
我只想要每个ID的描述之一,因为它们以不相关的方式不同:
ID Description
1 A popular place to eat!
2 Everyone, Lets go!
如何编写SQL查询以从表1生成表2?
答案 0 :(得分:4)
按您想要唯一的列进行分组,并使用description
列上的任何聚合函数,例如min()
或max()
select id, min(description)
from your_table
group by id