表结构: 提出行行号 提入行行号 笔数 120 050 1 120 051 2 120 052 3 120 053 4说明:提出行号和提入行号是指银行的编号,笔数是指票据的数量 就是说:从编号为120的银行提出的票据分别存入了编号为050,051,052,053的银行中 存入的票据数量分别是1,2,3,4
------------------------------------------------------------------------------------要求查询统计的结果为: 提入行行号 笔数 提入行行号 笔数 提出行行号
050 1 052 3 120
051 2 053 4 120
请问这样的SQL语句该怎样写???
------------------------------------------------------------------------------------要求查询统计的结果为: 提入行行号 笔数 提入行行号 笔数 提出行行号
050 1 052 3 120
051 2 053 4 120
请问这样的SQL语句该怎样写???
create table #temp(id int,row int,qty int)
insert into #temp(id,row,qty)
select 120,050,1
union all select 120,051,2
union all select 120,052,3
union all select 120,053,4create table #t1(id int identity(1,1),row int,qty int)
insert into #t1(row,qty)
select top 50 percent row,qty
from #temp order by rowcreate table #t2(id int identity(1,1),row int,qty int)
insert into #t2(row,qty)
select row,qty
from #temp
where row not in (select row from #t1)select isnull(#t1.row,'') as row,
isnull(#t1.qty,'') as qty,
isnull(#t2.row,'') as row,
isnull(#t2.qty,'') as qty
from #t1
left join #t2 on #t1.id = #t2.id and #t1.row <> #t2.rowdrop table #t1
drop table #t2
drop table #temp
揭贴了。