| 100 | {{{#!div style="font-size: 80%" |
| 101 | {{{#!sql |
| 102 | select a.tb_ime, a.interval_1h , a.broj_pati |
| 103 | from( |
| 104 | select tb_ime, interval_1h , count(tb_ime||'-'||interval_1h) broj_pati |
| 105 | from( |
| 106 | select *, |
| 107 | (to_char(extract (hour from b.b_datum_na_kupuvanje), '00') || ':00 -' || to_char(extract (hour from (b.b_datum_na_kupuvanje + '1 hours'::interval))::int, '00') || ':00') as interval_1h |
| 108 | from tipbilet t |
| 109 | left join bilet b on b.tb_id = t.tb_id |
| 110 | where b.b_datum_na_kupuvanje between (make_date(extract(year from (now() - '1 years'::interval))::int, 1, 1)) and (make_date(extract(year from (now() - '1 years'::interval))::int, 12, 31)) |
| 111 | ) |
| 112 | group by tb_ime, interval_1h |
| 113 | order by tb_ime, interval_1h |
| 114 | ) a |
| 115 | where broj_pati = ( |
| 116 | select max(broj_pati) |
| 117 | from( |
| 118 | select tb_ime, interval_1h , count(tb_ime||'-'||interval_1h) broj_pati |
| 119 | from( |
| 120 | select *, |
| 121 | (to_char(extract (hour from b.b_datum_na_kupuvanje), '00') || ':00 -' || to_char(extract (hour from (b.b_datum_na_kupuvanje + '1 hours'::interval))::int, '00') || ':00') as interval_1h |
| 122 | from tipbilet t |
| 123 | left join bilet b on b.tb_id = t.tb_id |
| 124 | where b.b_datum_na_kupuvanje between (make_date(extract(year from (now() - '1 years'::interval))::int, 1, 1)) and (make_date(extract(year from (now() - '1 years'::interval))::int, 12, 31)) |
| 125 | and tb_ime = a.tb_ime |
| 126 | ) |
| 127 | group by tb_ime, interval_1h |
| 128 | order by tb_ime, interval_1h |
| 129 | ) |
| 130 | -- group by tb_ime |
| 131 | ) and tb_ime in ('Часовен', 'Дневен') |
| 132 | |
| 133 | }}} |
| 134 | }}} |