| 1 | = Напредни извештаи од базата (SQL и складирани процедури) = |
| 2 | |
| 3 | === Извештај за број на закажани настани во секој од последните 3 месеци поединечно === |
| 4 | |
| 5 | {{{#!sql |
| 6 | select sum(ovoj_mesec.broj_nastani) as zakazani_nastani_ovoj_mesec, sum(prethoden_mesec.broj_nastani) as zakazani_nastani_prethoden_mesec, sum(predprethoden_mesec.broj_nastani) as zakazani_nastani_predprethoden_mesec |
| 7 | from nastani as n |
| 8 | left join( |
| 9 | select n.nastan_id as nastan_id, n.datum as nastan_datum, n.tip as tip_nastan, kb.ime as ime_bend, kk.ime as ime_ketering, kf.ime as ime_fotograf , count (*) as broj_nastani |
| 10 | from nastani as n |
| 11 | left join bend_sviri_nastan bsn on bsn.nastan_id = n.nastan_id |
| 12 | left join bendovi as b on b.korisnik_id = bsn.korisnik_id |
| 13 | left join korisnici kb on kb.korisnik_id = b.korisnik_id |
| 14 | |
| 15 | left join ketering_rezervira_nastan krn on krn.nastan_id = n.nastan_id |
| 16 | left join keterinzi as k on k.korisnik_id = krn.korisnik_id |
| 17 | left join korisnici kk on kk.korisnik_id = k.korisnik_id |
| 18 | |
| 19 | left join fotograf_slika_nastan fsn on fsn.nastan_id = n.nastan_id |
| 20 | left join fotografi as f on f.korisnik_id = fsn.korisnik_id |
| 21 | left join korisnici kf on kf.korisnik_id = f.korisnik_id |
| 22 | |
| 23 | where extract(month from n.datum) = extract(month from now()) and extract(year from n.datum) = extract(year from now()) |
| 24 | |
| 25 | group by 1,2,3,4,5,6 |
| 26 | |
| 27 | ) as ovoj_mesec on n.nastan_id = ovoj_mesec.nastan_id and n.tip = ovoj_mesec.tip_nastan |
| 28 | |
| 29 | left join( |
| 30 | select n.nastan_id as nastan_id, n.datum as nastan_datum, n.tip as tip_nastan, kb.ime as ime_bend, kk.ime as ime_ketering, kf.ime as ime_fotograf, count (*) as broj_nastani |
| 31 | from nastani as n |
| 32 | left join bend_sviri_nastan bsn on bsn.nastan_id = n.nastan_id |
| 33 | left join bendovi as b on b.korisnik_id = bsn.korisnik_id |
| 34 | left join korisnici kb on kb.korisnik_id = b.korisnik_id |
| 35 | |
| 36 | left join ketering_rezervira_nastan krn on krn.nastan_id = n.nastan_id |
| 37 | left join keterinzi as k on k.korisnik_id = krn.korisnik_id |
| 38 | left join korisnici kk on kk.korisnik_id = k.korisnik_id |
| 39 | |
| 40 | left join fotograf_slika_nastan fsn on fsn.nastan_id = n.nastan_id |
| 41 | left join fotografi as f on f.korisnik_id = fsn.korisnik_id |
| 42 | left join korisnici kf on kf.korisnik_id = f.korisnik_id |
| 43 | |
| 44 | where extract(month from n.datum) = extract(month from now() - interval '1 month') and extract(year from n.datum) = extract(year from now()- interval '1 month') |
| 45 | group by 1,2,3,4,5,6 |
| 46 | |
| 47 | ) as prethoden_mesec on n.nastan_id = prethoden_mesec.nastan_id and n.tip = prethoden_mesec.tip_nastan |
| 48 | |
| 49 | left join( |
| 50 | select n.nastan_id as nastan_id, n.datum as nastan_datum, n.tip as tip_nastan, kb.ime as ime_bend, kk.ime as ime_ketering, kf.ime as ime_fotograf, count (*) as broj_nastani |
| 51 | from nastani as n |
| 52 | left join bend_sviri_nastan bsn on bsn.nastan_id = n.nastan_id |
| 53 | left join bendovi as b on b.korisnik_id = bsn.korisnik_id |
| 54 | left join korisnici kb on kb.korisnik_id = b.korisnik_id |
| 55 | |
| 56 | left join ketering_rezervira_nastan krn on krn.nastan_id = n.nastan_id |
| 57 | left join keterinzi as k on k.korisnik_id = krn.korisnik_id |
| 58 | left join korisnici kk on kk.korisnik_id = k.korisnik_id |
| 59 | |
| 60 | left join fotograf_slika_nastan fsn on fsn.nastan_id = n.nastan_id |
| 61 | left join fotografi as f on f.korisnik_id = fsn.korisnik_id |
| 62 | left join korisnici kf on kf.korisnik_id = f.korisnik_id |
| 63 | |
| 64 | where extract(month from n.datum) = extract(month from now() - interval '2 month') and extract(year from n.datum) = extract(year from now()- interval '2 month') |
| 65 | group by 1,2,3,4,5,6 |
| 66 | ) as predprethoden_mesec on n.nastan_id = predprethoden_mesec.nastan_id and n.tip = predprethoden_mesec.tip_nastan |
| 67 | }}} |
| 68 | |
| 69 | |
| 70 | === Извештај за број на типови на алкохолни пијалоци конзумирани за секој настан заедно со името на клиентот кој го закажал,кетеринг групата која служела и бројот на келнери сортирани според датумот во растечки редослед === |
| 71 | |
| 72 | {{{#!sql |
| 73 | select n.nastan_id, n.datum, lista_klienti.ime as ime_klient, lista_keterinzi.ime as ime_ketering, count(lista_pijaloci) as broj_alkoholni_pijaloci, lista_keterinzi.kolicina as broj_kelneri |
| 74 | from nastani as n |
| 75 | |
| 76 | join ( |
| 77 | select * from korisnici as k |
| 78 | join klienti as kl on k.korisnik_id = kl.korisnik_id_korisnici |
| 79 | ) as lista_klienti on n.korisnik_id_klienti = lista_klienti.korisnik_id |
| 80 | |
| 81 | join( |
| 82 | select * from korisnici as k |
| 83 | join keterinzi as ke on k.korisnik_id = ke.korisnik_id |
| 84 | join ketering_rezervira_nastan as krn on ke.korisnik_id = krn.korisnik_id |
| 85 | ) as lista_keterinzi on n.nastan_id = lista_keterinzi.nastan_id |
| 86 | |
| 87 | join ( |
| 88 | select * from korisnici as k |
| 89 | join keterinzi as ke on k.korisnik_id = ke.korisnik_id |
| 90 | join ketering_nudi_produkt as knp on ke.korisnik_id = knp.korisnik_id |
| 91 | join produkti as p on knp.produkt_id = p.produkt_id |
| 92 | join pijaloci as pij on p.produkt_id = pij.produkt_id |
| 93 | join ketering_rezervira_nastan as krn on ke.korisnik_id = krn.korisnik_id |
| 94 | ) as lista_pijaloci on n.nastan_id = lista_pijaloci.nastan_id |
| 95 | |
| 96 | where lista_pijaloci.dali_alkoholen = true and n.datum between now()- interval '12 months' and now () |
| 97 | group by 1,2,3,4,6 |
| 98 | order by 2 asc |
| 99 | }}} |