declare @t table(字段1 char(4),字段2 char(4),字段3 int)
insert @t select '张三','北京',1 union
select '张三','北京',2 union
select '张三','北京',3 union
select '李四','天津',1 union
select '李四','天津',2 union
select '李四','天津',3
select
字段1=(case
when 字段3 = (select top 1 字段3 from @t where 字段1=a.字段1)
then a.字段1
else
' '
end),
字段2=(case
when 字段3 = (select top 1 字段3 from @t where 字段1=a.字段1)
then a.字段2
else
' '
end),
字段3
from @t a
declare @t table(字段1 char(4),字段2 char(4),字段3 int)
insert @t select '张三','北京',1 union
select '张三','北京',2 union
select '张三','北京',3 union
select '李四','天津',1 union
select '李四','天津',2 union
select '李四','天津',3
select 字段1=case when not exists(select 1 from @t where 字段1=a.字段1 and 字段2=a.字段2 and 字段3 < a.字段3)
then 字段1 else '' end ,
字段2=case when not exists(select 1 from @t where 字段1=a.字段1 and 字段2=a.字段2 and 字段3 < a.字段3)
then 字段2 else '' end ,
字段3 from @t a