仓库号,产品物料编码,产品物料名称,物料编码(子物料),物料名称,领用数量
001 A A1 100
001 A A2 80
001 A 小计 180
001 B B1 20
001 B 小计 20
001 合计 200
002 A A1 20
002 A 小计 20
002 合计 20
总计 220
001 A A1 100
001 A A2 80
001 A 小计 180
001 B B1 20
001 B 小计 20
001 合计 200
002 A A1 20
002 A 小计 20
002 合计 20
总计 220
inner join salary s on s.empid=e.id
group by d.departname with rollup在这上面改装一下.
(select cast(0 as int) as Ord_id,depotno,itemno,item_desc,subitemnno,subitem_desc,out_qty from tabA
union select 1,depotno,itemno,'小计','','',sum(out_qty) as sum_qty from tabA group by depotno,itemno
union select 2,depotno,'合计','','','',sum(out_qty) as total_qty from tabA group by depotno
union select 3,'总计','','','','',sum(out_qty) as total_qty from tabA
) a
order by depotno,ord_id,itemno
select * from
(select 0 as type,cast(0 as int) as Ord_id,depotno,itemno,item_desc,subitemnno,subitem_desc,out_qty from tabA
union select 0,1,depotno,itemno,'小计','','',sum(out_qty) as sum_qty from tabA group by depotno,itemno
union select 0,2,depotno,'合计','','','',sum(out_qty) as total_qty from tabA group by depotno
union select 1,3,'总计','','','','',sum(out_qty) as total_qty from tabA
) a
order by type,depotno,ord_id,itemno --此处的排序规则不可变以确保总计的记录显示在最后
怎么改,你说的清楚一些好吗??最好能针对我给
的表写出SELECT语句
001 A A1 100
001 A A2 80
001 A 小计 180
001 B B1 20
001 B 小计 20
001 合计 200
002 A A1 20
002 A 小计 20
002 合计 20
总计 220