我在数据库中有一些数据:
名称@ Country = Status Mary连美国待定 简·日本待定 简·韩国待定 禤浩焯.中国.待决 彼得·新加坡待定 Jack马来西亚待定 禤浩焯_中国更新 简·日本
我可以知道如何使用SELECT查询来选择没有重复数据的所有数据吗?(如果存在重复数据,则只选择状态和更新)
发布于 2013-06-18 01:50:02
尝试:
SELECT Name, Country, MAX(Status) as Status FROM (
SELECT TOP 100 PERCENT *
FROM NameCountry
ORDER BY Name ASC, Country ASC, Status DESC
) G
GROUP BY G.Name, G.Country
ORDER BY G.Name, G.Country检查我的演示
发布于 2013-06-18 01:41:45
从您的评论中,您似乎只表示前两列重复的数据。我认为,最简单的方法是使用row_number(),它可以在大多数数据库中使用:
select name, country, status
from (select t.*,
row_number() over (partition by name, country
order by (case when status = 'Pending' then 0 else 1 end)
) as seqnum
from t
) t
where seqnum = 1https://stackoverflow.com/questions/17159351
复制相似问题