获取分组中前几条数据 top order by

 

DECLARE @temp TABLE(  

id INT,  

[name] VARCHAR(50),  

class VARCHAR(50)  

)  

INSERT INTO @temp  

SELECT 1,'a','A'  

UNION ALL SELECT 2,'b','C'  

UNION ALL SELECT 3,'c','B'  

UNION ALL SELECT 4,'d','C'  

UNION ALL SELECT 5,'e','B'  

UNION ALL SELECT 6,'f','A'  

 

SELECT * FROM @temp AS _temp WHERE [name] IN   

(  

SELECT TOP 1 [name] FROM @temp WHERE _temp.class=class ORDER BY id DESC   

)  

ORDER BY class  

 

posted @   洗碗心得  阅读(437)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示