这sql 语句写的真的很不错!
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col1] bigint,[col2] varchar(6),[col3] varchar(6))
insert [tb]
select 130126200201000275,'王文霞','靳川川' union all
select 130126200201000275,'王文霞','靳澤' union all
select 130126200201000275,'王文霞','aaaa' union all
select 130126200201000276,'周書娥','程思超' union all
select 130126200201000276,'周書娥','程佼佼' union all
select 130126200201000277,'風菊','程青青' union all
select 130126200201000277,'風菊','程二小' union all
select 130126200201000278,'張英桃','程大慶' union all
select 130126200201000278,'張英桃','程小花'
--------------开始查询--------------------------
select * from tb
select col2,col3 from
(
select col1,col2,col3 from [tb] t
where not exists(select * from tb where col1=t.col1 and col2=t.col2 and col3>t.col3)
union all
select col1,'',col3 from [tb] t
where exists(select 1 from tb where col1=t.col1 and col2=t.col2 and col3>t.col3)
)T
order by col1,col3 desc