日期:2014-05-17 浏览次数:20434 次
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (字段A int,字段B int,字段C int,字段D int,字段E int)
insert into [TB]
select 1,1,1,0,0 union all
select 2,1,1,2,2 union all
select 3,1,1,2,3 union all
select 4,1,1,0,0 union all
select 5,1,1,2,2 union all
select 6,1,1,4,4
select * from [TB]
;WITH TT
AS(
SELECT ROW_NUMBER() OVER(PARTITION BY 字段D,字段E ORDER BY 字段A) AS NO,*
FROM dbo.TB)
SELECT 字段A ,字段B ,字段C,字段D ,字段E FROM TT WHERE no =1
/*
字段A 字段B 字段C 字段D 字段E
1 1 1 0 0
2 1 1 2 2
3 1 1 2 3
6 1 1 4 4*/