| | 3 | ===Извештај за квартално продадени автомобили и приход на едно застапништво (во овој случај БМВ М Кар), како и просечен месечен профит во тој период. |
| | 4 | {{{ |
| | 5 | select |
| | 6 | ( |
| | 7 | select count(a.a_id) from dealership as d |
| | 8 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 9 | where (extract(month from a.datum) between 1 and 3) |
| | 10 | and (extract(year from a.datum)=2023) |
| | 11 | and d.d_name='BMW M-Kar' |
| | 12 | ) as first_quartal_sold_cars, |
| | 13 | ( |
| | 14 | select sum(a.price) from dealership as d |
| | 15 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 16 | where (extract(month from a.datum) between 1 and 3) |
| | 17 | and (extract(year from a.datum)=2023) |
| | 18 | and d.d_name='BMW M-Kar' |
| | 19 | ) as first_quartal_profit, |
| | 20 | ( |
| | 21 | select count(a.a_id) from dealership as d |
| | 22 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 23 | where (extract(month from a.datum) between 4 and 6) |
| | 24 | and (extract(year from a.datum)=2023) |
| | 25 | and d.d_name='BMW M-Kar' |
| | 26 | ) as second_quartal_sold_cars, |
| | 27 | ( |
| | 28 | select sum(a.price) from dealership as d |
| | 29 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 30 | where (extract(month from a.datum) between 4 and 6) |
| | 31 | and (extract(year from a.datum)=2023) |
| | 32 | and d.d_name='BMW M-Kar' |
| | 33 | ) as second_quartal_profit, |
| | 34 | ( |
| | 35 | select count(a.a_id) from dealership as d |
| | 36 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 37 | where (extract(month from a.datum) between 7 and 9) |
| | 38 | and (extract(year from a.datum)=2023) |
| | 39 | and d.d_name='BMW M-Kar' |
| | 40 | ) as third_quartal_sold_cars, |
| | 41 | ( |
| | 42 | select sum(a.price) from dealership as d |
| | 43 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 44 | where (extract(month from a.datum) between 7 and 9) |
| | 45 | and (extract(year from a.datum)=2023) |
| | 46 | and d.d_name='BMW M-Kar' |
| | 47 | ) as third_quartal_profit, |
| | 48 | ( |
| | 49 | select count(a.a_id) from dealership as d |
| | 50 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 51 | where (extract(month from a.datum) between 10 and 12) |
| | 52 | and (extract(year from a.datum)=2023) |
| | 53 | and d.d_name='BMW M-Kar' |
| | 54 | ) as fourth_quartal_sold_cars, |
| | 55 | ( |
| | 56 | select sum(a.price) from dealership as d |
| | 57 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 58 | where (extract(month from a.datum) between 10 and 12) |
| | 59 | and (extract(year from a.datum)=2023) |
| | 60 | and d.d_name='BMW M-Kar' |
| | 61 | ) as fourth_quartal_profit, |
| | 62 | ( |
| | 63 | select sum(a.price)/12 from dealership as d |
| | 64 | left join agreement as a on a.tax_nr=d.tax_nr |
| | 65 | where d.d_name='BMW M-Kar' |
| | 66 | ) as average_monthly_profit; |
| | 67 | }}} |