我有这张桌子:
id name type creator reason guild
1 hi in 322
2 hi out some 322
3 hi in 322
4 ok in 322
我希望名称,类型和行会名称不同的所有列和行
select distinct name, type, guild
但是我也想在上面的结果中保留其他列,我正在使用sqlite数据库
以上内容的输出
hi in 322
hi out 322
ok in 322
输出缺少其他列
答案 0 :(得分:0)
row_number()
通常用于此目的:
select p.*
from (select p.*, row_number() over (partition by name, type, guild order by name) as seqnum
from players p
) p
where seqnum = 1;
答案 1 :(得分:0)
从注释中看来,您需要按ID排序的row_number()
select name, type, guild,creator,reason
from (select name, type, guild,creator,reason,
row_number()
over (partition by name, type, guild order by guild) as rn
from players
) t
where rn = 1;