| 1 | == Просечна цена на продуктот во месец од изминатите 12 месеци == |
| 2 | {{{#!sql |
| 3 | select |
| 4 | sum(case when extract(month from ph.dates) =1 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =1 and now() - interval'12 months' <= ph.dates then ph.price end) as Januari, |
| 5 | sum(case when extract(month from ph.dates) =2 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =2 and now() - interval'12 months' <= ph.dates then ph.price end) as Fevruari, |
| 6 | sum(case when extract(month from ph.dates) =3 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =3 and now() - interval'12 months' <= ph.dates then ph.price end) as Mart, |
| 7 | sum(case when extract(month from ph.dates) =4 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =4 and now() - interval'12 months' <= ph.dates then ph.price end) as April, |
| 9 | sum(case when extract(month from ph.dates) =5 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =5 and now() - interval'12 months' <= ph.dates then ph.price end) as Maj, |
| 10 | sum(case when extract(month from ph.dates) =6 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =6 and now() - interval'12 months' <= ph.dates then ph.price end) as Juni, |
| 11 | sum(case when extract(month from ph.dates) =7 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =7 and now() - interval'12 months' <= ph.dates then ph.price end) as Juli, |
| 12 | sum(case when extract(month from ph.dates) =8 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =8 and now() - interval'12 months' <= ph.dates then ph.price end) as Avgust, |
| 13 | |
| 14 | sum(case when extract(month from ph.dates) =9 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =9 and now() - interval'12 months' <= ph.dates then ph.price end) as Septemvri, |
| 15 | sum(case when extract(month from ph.dates) =10 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =10 and now() - interval'12 months' <= ph.dates then ph.price end) as Oktomvri, |
| 16 | sum(case when extract(month from ph.dates) =11 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =11 and now() - interval'12 months' <= ph.dates then ph.price end) as Noemvri, |
| 17 | sum(case when extract(month from ph.dates) =12 and now() - interval'12 months' <= ph.dates then ph.price end)/count(case when extract(month from ph.dates) =12 and now() - interval'12 months' <= ph.dates then ph.price end) as Dekemvri |
| 18 | from project.price_history as ph |
| 19 | where prod_id = 3250; |
| 20 | }}} |