Rapoarte PostgreSQL
Rapoarte PostgreSQL
Vanzari
Produs
2008
2009
2010
Total
Produs 1
Produs 2
Produs 3
...
1. Solutia 1 - CASE
select denpr, sum(case when extract(year from datafact)=2008 then
cantitate*pretunit
else 0 end) as v_2008, sum(case when extract(year from
datafact)=2009 then cantitate*pretunit
else 0 end) as v_2009, sum(case when extract(year from
datafact)=2010 then cantitate*pretunit
else 0 end) as v_2010,
sum(cantitate*pretunit) as total
from facturi f inner join liniifact lf on f.nrfact=lf.nrfact
inner join produse p on p.codpr=lf.codpr
where extract(year from datafact) between 2008 and 2010
group by denpr order by 1