34,591
社区成员
发帖
与我相关
我的任务
分享
with cte1 as
(
select top 20 a.c_gcode,b.c_name,sum(a.c_amount),sum(a.c_qtty),substring(a.c_adno,1,3)
from tb_o_sg as a,tb_gds as b
where a.c_gcode=b.c_gcode and a.c_adno like '101___' and a.c_datetime>='2011-06-01' and a.c_datetime<'2011-06-03'
group by a.c_gcode,b.c_name,a.c_adno
order by sum(a.c_amount) desc)
,cte2 as
(
select top 20 a.c_gcode,b.c_name,sum(a.c_amount),sum(a.c_qtty),substring(a.c_adno,1,3)
from tb_o_sg as a,tb_gds as b
where a.c_gcode=b.c_gcode and a.c_adno like '102___' and a.c_datetime>='2011-06-01' and a.c_datetime<'2011-06-03'
group by a.c_gcode,b.c_name,a.c_adno
order by sum(a.c_amount) desc
)
select * from cte1
union all
select * from cte2