select
a.编号,
客户=case when exists(select 1 from t where 客户=a.客户 and 编号<a.编号) then '' else a.客户 end,
客户订货产品
from
t a
order by
a.编号
a.编号,
客户=case when exists(select 1 from t where 客户=a.客户 and 编号<a.编号) then '' else a.客户 end,
客户订货产品
from
t a
order by
a.编号
set 客户=''
from #a,
(select 编号 from #a where 编号 not in (select min(编号) from #a group by 客户)) #b
where #a.编号 = #b.编号select * from #t
(
编号 int identity(1,1),
客户 varchar(10),
订货产品 varchar(10)
)
insert test
select '无锡', '钢材' union all
select '无锡', '汽配件' union all
select '无锡', '电线' union all
select '北京', '烤鸭' union all
select '北京', '湖南鱼' union all
select '重庆', '火锅'
select * from testselect 编号,客户,订货产品 from test where 编号 in(select
min(编号) from test group by 客户)
union all
select 编号,'',订货产品 from test where 编号 not in
(
select min(编号) from test group by 客户
) order by 编号
drop table test
--创建测试数据
declare @t table (编号 int, 客户 varchar(100),订货产品 varchar(100))insert into @t
select 1,'无锡','钢材' union all
select 2,'无锡','汽配件' union all
select 3,'无锡','电线' union all
select 4,'北京','烤鸭' union all
select 5,'北京','湖南鱼' union all
select 6,'重庆','火锅'select * from @tselect
A.编号,
case when 编号=(select min(编号) from @t where 客户=A.客户) then A.客户 else '' end as 客户,
A.订货产品
from @t A
order by A.编号