我有两个选择语句。1stselect
返回 2012 年的数据,而 2ndselect
显示当前年份。我将如何加入这两个以获得我想要的输出。
select a.id, b.item, a.sum(qty) as 'yr1qty', a.yr1amt from table A
left join table B on a.code = b.code
where date between '04/01/2012' and '04/07/2012'
group by a.id, b. item
select a.id, b.item, a.sum(qty) as 'yr2qty', a.yr2amt from table A
left join table B on a.code = b.code
where date between '04/01/2013' and '04/07/2013'
group by a.id, b. item
所需的输出:
id item yr1qty y1amt yr2qty yr2amt
01 item01 20 2000.00 5 500.00
02 item02 8 400.00
03 item03 10 1250.00
04 item04 3 60.00 2 40.00
05 item05 8 400.00