140 | | select k.naslov, a.ime, count(p.id_na_pozajmica) as pozajmuvanja from |
141 | | pozajmica as p |
142 | | |
143 | | join knigi as k on p.id_na_kniga=k.id_na_kniga |
144 | | join izdava as i on k.id_na_kniga = i.id_knigi |
145 | | join avtor as a on i.id_avtor = a.id_na_avtor |
146 | | where a.ime like '%Goce%' and p.datum_na_zemanje between now() - interval'6 weeks' and now() |
147 | | |
148 | | group by 1,2 |
149 | | order by pozajmuvanja desc |
| 139 | select mesectri.naslov, mesectri.ime,mesectri.pozajmuvanja_pomegju_2_3_meseci_nanazad, |
| 140 | mesecdva.naslov, mesecdva.ime,mesecdva.pozajmuvanja_pomegju_1_2_meseci_nanazad, meseceden.naslov, meseceden.ime,meseceden.pozajmuvanja_za_posledniot_mesec |
| 141 | from |
| 142 | ( |
| 143 | select k.naslov, a.ime, count(p.id_na_pozajmica) as pozajmuvanja_za_posledniot_mesec from |
| 144 | pozajmica as p |
| 145 | |
| 146 | join knigi as k on p.id_na_kniga=k.id_na_kniga |
| 147 | join izdava as i on k.id_na_kniga = i.id_knigi |
| 148 | join avtor as a on i.id_avtor = a.id_na_avtor |
| 149 | where a.ime like '%Goce%' and p.datum_na_zemanje between now() - interval'1 month' and now() |
| 150 | |
| 151 | group by 1,2 |
| 152 | order by pozajmuvanja_za_posledniot_mesec desc |
| 153 | fetch first row only |
| 154 | |
| 155 | ) as meseceden |
| 156 | join |
| 157 | ( |
| 158 | select k.naslov, a.ime, count(p.id_na_pozajmica) as pozajmuvanja_pomegju_1_2_meseci_nanazad from |
| 159 | pozajmica as p |
| 160 | |
| 161 | join knigi as k on p.id_na_kniga=k.id_na_kniga |
| 162 | join izdava as i on k.id_na_kniga = i.id_knigi |
| 163 | join avtor as a on i.id_avtor = a.id_na_avtor |
| 164 | where a.ime like '%Goce%' and p.datum_na_zemanje between now() - interval'2 months' and now() - interval'1month' |
| 165 | |
| 166 | group by 1,2 |
| 167 | order by pozajmuvanja_pomegju_1_2_meseci_nanazad desc |
| 168 | fetch first row only |
| 169 | |
| 170 | ) as mesecdva on meseceden.ime = mesecdva.ime |
| 171 | join |
| 172 | ( |
| 173 | select k.naslov, a.ime, count(p.id_na_pozajmica) as pozajmuvanja_pomegju_2_3_meseci_nanazad from |
| 174 | pozajmica as p |
| 175 | |
| 176 | join knigi as k on p.id_na_kniga=k.id_na_kniga |
| 177 | join izdava as i on k.id_na_kniga = i.id_knigi |
| 178 | join avtor as a on i.id_avtor = a.id_na_avtor |
| 179 | where a.ime like '%Goce%' and p.datum_na_zemanje between now() - interval'3 months' and now() - interval'2 months' |
| 180 | |
| 181 | group by 1,2 |
| 182 | order by pozajmuvanja_pomegju_2_3_meseci_nanazad desc |
| 183 | fetch first row only |
| 184 | ) as mesectri on mesecdva.ime = mesectri.ime |
154 | | select ch.ime,ch.prezime,(count(a.log_id)) as najavuvanja |
155 | | from authentication as a |
156 | | |
157 | | join chovek as ch on a.id_chovek = ch.id_chovek |
158 | | where a.timestamp_log between now() - interval '2 weeks' and now() |
159 | | |
160 | | group by 1,2 |
161 | | order by najavuvanja desc |
162 | | }}} |
| 189 | select mesectri.ime, mesectri.prezime, meseceden.najavuvanja_vo_prethoden_mesec, |
| 190 | mesecdva.najavuvanja_izmegju_1_2_meseci_nanazad, mesectri.najavuvanja_izmegju_2_3_meseci_nanazad |
| 191 | from |
| 192 | ( |
| 193 | select ch.ime,ch.prezime,(count(a.log_id)) as najavuvanja_vo_prethoden_mesec |
| 194 | from authentication as a |
| 195 | |
| 196 | join chovek as ch on a.id_chovek = ch.id_chovek |
| 197 | where a.timestamp_log between now() - interval '1 month' and now() |
| 198 | |
| 199 | group by 1,2 |
| 200 | order by najavuvanja_vo_prethoden_mesec desc |
| 201 | ) as meseceden |
| 202 | join |
| 203 | ( |
| 204 | select ch.ime,ch.prezime,(count(a.log_id)) as najavuvanja_izmegju_1_2_meseci_nanazad |
| 205 | from authentication as a |
| 206 | |
| 207 | join chovek as ch on a.id_chovek = ch.id_chovek |
| 208 | where a.timestamp_log between now() - interval '2 months' and now() - interval '1 month' |
| 209 | |
| 210 | group by 1,2 |
| 211 | order by najavuvanja_izmegju_1_2_meseci_nanazad desc |
| 212 | ) as mesecdva on meseceden.ime = mesecdva.ime and meseceden.prezime = mesecdva.prezime |
| 213 | join |
| 214 | ( |
| 215 | select ch.ime,ch.prezime,case when count(a.log_id) is null then 0 else count(a.log_id) end as najavuvanja_izmegju_2_3_meseci_nanazad |
| 216 | from authentication as a |
| 217 | |
| 218 | join chovek as ch on a.id_chovek = ch.id_chovek |
| 219 | where a.timestamp_log between now() - interval '3 months' and now() - interval '2 months' |
| 220 | |
| 221 | group by 1,2 |
| 222 | order by najavuvanja_izmegju_2_3_meseci_nanazad desc |
| 223 | }}} |