日期:2014-05-17 浏览次数:20543 次
create Table #TestA (ID varchar(50),姓名 varchar(20),车间号 varchar(10),金钱 money)
insert into #TestA
select 'AABBCC','小名','A20',300 union all
select 'AABBCC','小红','A20',200 union all
select 'DDFFCC','小军','D20',400 union all
select 'DDFFCC','小李','D20',800
go
create Table #TestB (ID varchar(50),姓名 varchar(20),车间号 varchar(10),金钱 money)
insert into #TestB
select 'AABBCC','小计','A20',500 union all
select 'AABBCC','小计','D20',1200
select *from #TestA
select *from #TestB
select 'AABBCC'as ID,'小名'as 姓名,'A20'as 车间号,300 as 金钱 union all
select 'AABBCC','小红','A20',200 union all
select 'AABBCC','小计','A20',500 union all
select 'DDFFCC','小军','D20',400 union all
select 'DDFFCC','小李','D20',800 union all
select 'AABBCC','小计','D20',1200
select ID,姓名,车间号,金钱
from
(
select *,1 as v from #TestA
union all
select *,2 from #TestB
)t
order by id,v
/*
ID 姓名 车间号 金钱
AABBCC 小名 A20 300.00
AABBCC 小红 A20 200.00
AABBCC 小计 A20 500.00
DDFFCC 小军 D20 400.00
DDFFCC 小李 D20 800.00
DDFFCC 小计 D20 1200.00
*/
create Table #TestA (ID varchar(10),姓名 varchar(10),车间号 varchar(10),金钱 money)
insert into #TestA
select 'AABBCC','小名','A20',300 union all
select 'AABBCC','小红','A20',200 union all
select 'DDFFCC','小军','D20',400 union all
select 'DDFFCC','小李','D20',800
create Table #TestB (ID varchar(10),姓名 varchar(10),车间号 varchar(10),金钱 money)
insert into #TestB
select 'AABBCC','小计','A20',500 union all
select 'DDFFCC','小计','D20',1200
select *
from
(select * from #TestA
union all
select * from #TestB) t
order by ID,case when 姓名<>'小计' then 1 else 2 end
/*
ID 姓名 &n