J'ai deux instructions select. 1er select
renvoie les données de l'année précédente 2012, tandis que 2nd select
affiche l'année en cours. Comment vais-je rejoindre ces deux pour obtenir ma sortie désirée.Joindre deux instruction select en sql
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
sortie désirée:
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
est-ce vraiment un.y1amt ou est-ce sum (a.qty) que yr1amt? –