SQL组由最大不需要结果
我正在使用SQL Server 2014,并有一个表格:
PK ContactID Tele Mob Land Email Txt
1 10 1 0 1 1 1
2 10 0 1 0 0 1
3 12 1 3 1 1 1
所需的结果是:
PK ContactID Tele Mob Land Email Txt
2 10 0 1 0 0 1
3 12 1 3 1 1 1
但是,如果我执行Groupby \ Max:
SELECT MAX(PK) AS PK, ContactID, Tele, Mob, Land, Email, Txt
FROM Contacts
GROUP BY ContactID, Tele, Mob, Land, Email, Txt
我只是收到:
PK ContactID Tele Mob Land Email Txt
1 10 1 0 1 1 1
2 10 0 1 0 0 1
3 12 1 3 1 1 1
如何修改以给我预期的结果?
I'm using SQL Server 2014 and have a table like this:
PK ContactID Tele Mob Land Email Txt
1 10 1 0 1 1 1
2 10 0 1 0 0 1
3 12 1 3 1 1 1
The desired result is:
PK ContactID Tele Mob Land Email Txt
2 10 0 1 0 0 1
3 12 1 3 1 1 1
However, if I perform a GroupBy \ Max:
SELECT MAX(PK) AS PK, ContactID, Tele, Mob, Land, Email, Txt
FROM Contacts
GROUP BY ContactID, Tele, Mob, Land, Email, Txt
I'm just receiving:
PK ContactID Tele Mob Land Email Txt
1 10 1 0 1 1 1
2 10 0 1 0 0 1
3 12 1 3 1 1 1
How do I modify to give me the desired results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解,您可以尝试使用
row_number
窗口函数来制作它。If I understand correctly, you can try to use
ROW_NUMBER
window function to make it.最后一个由pk行使用
ties
的contactID进行contactidThe last by PK row for a ContactId using
top with ties