【sql基础】按照名字分组查询时间最早的⼀条记录给出2种解决⽅案
rownumber
distinct查询SELECT*
FROM
(
SELECT IdentityID, OpenID, ROW_NUMBER() OVER(PARTITION BY OpenID ORDER BY CreateTime DESC
) AS rownumber FROM dbo.T_Account
) AS tmp
wnumber =1
相关⼦查询
SELECT DISTINCT OpenID, test1.IdentityID FROM dbo.T_Account
AS test1
WHERE test1.IdentityID
IN
(
SELECT TOP1 IdentityID FROM dbo.T_Account
WHERE dbo.T_Account.OpenID = test1.OpenID
ORDER BY CreateTime DESC
)
查询结果
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论