| 87 | |
| 88 | ==== 7. Вкупна заработувачка од билети и казни на претпријатието во минатата календарска година |
| 89 | |
| 90 | {{{#!div style="font-size: 80%" |
| 91 | {{{#!sql |
| 92 | select |
| 93 | CASE |
| 94 | WHEN sum_kz IS NOT NULL AND sum_b IS NOT NULL THEN COALESCE(sum_kz::int, 0) + COALESCE(sum_b::int, 0) |
| 95 | WHEN sum_kz IS NOT NULL THEN COALESCE(sum_kz::int, 0) |
| 96 | WHEN sum_b IS NOT NULL THEN COALESCE(sum_b::int, 0) |
| 97 | ELSE 0 |
| 98 | END |
| 99 | from ( |
| 100 | select |
| 101 | ( |
| 102 | select sum(kz_iznos) |
| 103 | from kazna k |
| 104 | where k.kz_plateno = true and (k.kz_datum between (make_date(extract(year from (now() - '1 years'::interval))::int, 1, 1)) and |
| 105 | (make_date(extract(year from (now() - '1 years'::interval))::int, 12, 31))) |
| 106 | and (k.kz_datum_plateno between (make_date(extract(year from (now() - '1 years'::interval))::int, 1, 1)) and |
| 107 | (make_date(extract(year from (now() - '1 years'::interval))::int, 12, 31))) |
| 108 | ) sum_kz, |
| 109 | ( |
| 110 | select sum(tb_cena) |
| 111 | from bilet b |
| 112 | join tipbilet tb on tb.tb_id = b.tb_id |
| 113 | where b.b_datum_na_kupuvanje between (make_date(extract(year from (now() - '1 years'::interval))::int, 1, 1)) and |
| 114 | (make_date(extract(year from (now() - '1 years'::interval))::int, 12, 31)) |
| 115 | ) sum_b |
| 116 | ) |
| 117 | |
| 118 | }}} |
| 119 | }}} |