5 | | select kat.ime_kategorija,count(kat.ime_kategorija) as pozajmeni_knigi_od_kategorija |
6 | | from pozajmica as p |
7 | | |
8 | | join knigi as k on p.id_na_kniga = k.id_na_kniga |
9 | | join e_od as e on k.id_na_kniga = e.id_knigi |
10 | | join kategorija as kat on e.id_na_kategorija = kat.id_na_kategorija |
11 | | |
12 | | where p.datum_na_zemanje between now() - interval'3 weeks' and now() |
13 | | group by 1 |
14 | | order by pozajmeni_knigi_od_kategorija desc |
| 5 | select mesectri.ime_kategorija, mesectri.pozajmeni_za_prethodni_tri_meseci, |
| 6 | mesecdva.ime_kategorija, mesecdva.pozajmeni_za_prethodni_dva_meseci, |
| 7 | meseceden.ime_kategorija, meseceden.pozajmeni_za_prethoden_mesec |
| 8 | from |
| 9 | ( |
| 10 | select kat.ime_kategorija,count(kat.ime_kategorija) as pozajmeni_za_prethoden_mesec |
| 11 | from pozajmica as p |
| 12 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 13 | join e_od as e on k.id_na_kniga = e.id_knigi |
| 14 | join kategorija as kat on e.id_na_kategorija = kat.id_na_kategorija |
| 15 | where p.datum_na_zemanje between now() - interval'1 months' and now() |
| 16 | group by 1 |
| 17 | order by pozajmeni_za_prethoden_mesec desc |
| 18 | ) as meseceden |
| 19 | join |
| 20 | ( |
| 21 | select kat.ime_kategorija,count(kat.ime_kategorija) as pozajmeni_za_prethodni_dva_meseci |
| 22 | from pozajmica as p |
| 23 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 24 | join e_od as e on k.id_na_kniga = e.id_knigi |
| 25 | join kategorija as kat on e.id_na_kategorija = kat.id_na_kategorija |
| 26 | where p.datum_na_zemanje between now() - interval'2 months' and now() - interval'1 month' |
| 27 | group by 1 |
| 28 | order by pozajmeni_za_prethodni_dva_meseci desc |
| 29 | ) as mesecdva on meseceden.ime_kategorija = mesecdva.ime_kategorija |
| 30 | join |
| 31 | ( |
| 32 | select kat.ime_kategorija,count(kat.ime_kategorija) as pozajmeni_za_prethodni_tri_meseci |
| 33 | from pozajmica as p |
| 34 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 35 | join e_od as e on k.id_na_kniga = e.id_knigi |
| 36 | join kategorija as kat on e.id_na_kategorija = kat.id_na_kategorija |
| 37 | where p.datum_na_zemanje between now() - interval'3 months' and now() - interval'2 months' |
| 38 | group by 1 |
| 39 | order by pozajmeni_za_prethodni_tri_meseci desc |
| 40 | ) as mesectri on mesecdva.ime_kategorija = mesectri.ime_kategorija; |
19 | | select ch.ime,ch.prezime,(count(ch.id_chovek)) as pozajmuvanja |
20 | | from pozajmica as p |
| 45 | select mesectri.ime, mesectri.prezime, mesecTri.pozajmuvanja_pomegju_2_3_meseci_nanazad,meseceden.ime, meseceden.prezime, meseceden.pozajmuvanja_za_prethodniot_mesec, |
| 46 | mesecdva.ime, mesecdva.prezime, mesecdva.pozajmuvanja_pomegju_1_2_meseci_nanazad |
| 47 | from |
| 48 | ( |
| 49 | select ch.ime,ch.prezime,count(ch.ime) as pozajmuvanja_za_prethodniot_mesec |
| 50 | from pozajmica as p |
| 51 | join chlen as chl on p.id_chovek_prave = chl.id_chovek |
| 52 | join chovek as ch on chl.id_chovek = ch.id_chovek |
| 53 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 54 | where p.datum_na_zemanje between now() - interval'1 month' and now() |
| 55 | group by 1,2 |
| 56 | order by pozajmuvanja_za_prethodniot_mesec desc |
| 57 | ) as meseceden |
| 58 | join |
| 59 | ( |
| 60 | select ch.ime,ch.prezime,(count(ch.id_chovek)) as pozajmuvanja_pomegju_1_2_meseci_nanazad |
| 61 | from pozajmica as p |
| 62 | join chlen as chl on p.id_chovek_prave = chl.id_chovek |
| 63 | join chovek as ch on chl.id_chovek = ch.id_chovek |
| 64 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 65 | where p.datum_na_zemanje between now() - interval'2 months' and now() - interval '1 month' |
| 66 | group by 1,2 |
| 67 | order by pozajmuvanja_pomegju_1_2_meseci_nanazad desc |
| 68 | ) as mesecdva on meseceden.ime = mesecdva.ime |
| 69 | join |
| 70 | ( |
| 71 | select ch.ime,ch.prezime,(count(ch.id_chovek)) as pozajmuvanja_pomegju_2_3_meseci_nanazad |
| 72 | from pozajmica as p |
| 73 | join chlen as chl on p.id_chovek_prave = chl.id_chovek |
| 74 | join chovek as ch on chl.id_chovek = ch.id_chovek |
| 75 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 76 | where p.datum_na_zemanje between now() - interval'3 months' and now() - interval '2 months' |
| 77 | group by 1,2 |
| 78 | order by pozajmuvanja_pomegju_2_3_meseci_nanazad desc |
| 79 | ) as mesectri on mesecdva.ime = mesectri.ime |
33 | | select count(p.id_na_pozajmica) as pozajmici |
| 87 | select count(p.id_na_pozajmica) as meseceden, |
| 88 | ( |
| 89 | select count(p.id_na_pozajmica) as pozajmici |
| 90 | |
| 91 | from pozajmica as p |
| 92 | |
| 93 | join chlen as chl on p.id_chovek_prave = chl.id_chovek |
| 94 | join chovek as ch on chl.id_chovek = ch.id_chovek |
| 95 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 96 | |
| 97 | where age(((case when substr(ch.embg,5,1) = '9' then '1' || substr(ch.embg,5,3) |
| 98 | else '2' || substr(ch.embg,5,3) end) || '-' || substr(ch.embg,3,2) || '-' || substr(ch.embg,1,2))::date) between interval '20 years' and interval '22 years' |
| 99 | and p.datum_na_zemanje between now() - interval'2 months' and now() - interval '1 month' |
| 100 | |
| 101 | ) as mesecdva, |
| 102 | ( |
| 103 | select count(p.id_na_pozajmica) as pozajmici |
| 104 | |
| 105 | from pozajmica as p |
| 106 | |
| 107 | join chlen as chl on p.id_chovek_prave = chl.id_chovek |
| 108 | join chovek as ch on chl.id_chovek = ch.id_chovek |
| 109 | join knigi as k on p.id_na_kniga = k.id_na_kniga |
| 110 | |
| 111 | where age(((case when substr(ch.embg,5,1) = '9' then '1' || substr(ch.embg,5,3) |
| 112 | else '2' || substr(ch.embg,5,3) end) || '-' || substr(ch.embg,3,2) || '-' || substr(ch.embg,1,2))::date) between interval '20 years' and interval '22 years' |
| 113 | and p.datum_na_zemanje between now() - interval'3 months' and now() - interval'2 months' |
| 114 | |
| 115 | ) as mesectri |
40 | | where age(((case when substr(embg,5,1) = '9' then '1' || substr(embg,5,3) |
41 | | else '2' || substr(embg,5,3) end) || '-' || substr(embg,3,2) || '-' || substr(embg,1,2))::date) between interval '20 years' and interval '22 years' |
42 | | and p.datum_na_zemanje between now() - interval'3 weeks' and now() |
| 122 | where age(((case when substr(ch.embg,5,1) = '9' then '1' || substr(ch.embg,5,3) |
| 123 | else '2' || substr(ch.embg,5,3) end) || '-' || substr(ch.embg,3,2) || '-' || substr(ch.embg,1,2))::date) between interval '20 years' and interval '22 years' |
| 124 | and p.datum_na_zemanje between now() - interval'1 month' and now() |