日期:2014-05-18 浏览次数:20684 次
declare @T table (col1 int,col2 varchar(1),col3 varchar(1),col4 varchar(1)) insert into @T select 123,'a','b','c' union all select 123,'a','b','d' union all select 123,'a','b','c' union all select 456,'e','f','h' union all select 456,'e','f','h' select TOP 2 * from @T /* col1 col2 col3 col4 ----------- ---- ---- ---- 123 a b c 123 a b d */
------解决方案--------------------
WITH CTE AS( SELECT *,ROW_NUMBER() OVER(PARTITION BY 行号,字段1,字段2,字段3) AS RN FROM 表 ) SELECT * FROM CTE WHERE RN = 1