以下SQL用于在LastDate中存在差异时识别唯一的电话。 但是,如果重复的手机具有完全相同的LastDate,则它不起作用。
任何想法都会受到赞赏。
SELECT * FROM
(
SELECT ID, Phone, [LastDate]
,RANK() OVER (PARTITION BY Phone ORDER BY [LastDate]) AS 'RANK',
COUNT(Phone) OVER (PARTITION BY Phone) AS 'MAXCOUNT'
FROM MyTable
WHERE Groupid = 5
) a
WHERE [RANK] = [MAXCOUNT]
答案 0 :(得分:13)
更改RANK
的{{1}}。
ROW_NUMBER