查询日期最早的一条记录

SELECT DISTINCT OpenID, test1.IdentityID FROM dbo.T_Account 
AS test1
WHERE test1.IdentityID
IN 
(
SELECT TOP 1 IdentityID FROM dbo.T_Account
WHERE dbo.T_Account.OpenID =  test1.OpenID
ORDER BY CreateTime DESC

)

 

 

 

SELECT *
FROM
(
SELECT IdentityID, OpenID, ROW_NUMBER() OVER(PARTITION BY OpenID ORDER BY CreateTime DESC
) AS rownumber FROM dbo.T_Account
) AS tmp
WHERE tmp.rownumber = 1

 

posted @ 2021-12-02 16:07  秋刀鱼罐头  阅读(182)  评论(0编辑  收藏  举报