38 | | drop view if exists vkupen_broj_naracki; |
39 | | create view vkupen_broj_naracki as |
40 | | |
41 | | select n.korisnicko_ime,n.e_posta,count(dost.id_dostavuvanja) as broj_naracki |
42 | | from dostavuvaci as d |
43 | | join korisnici as n on d.korisnicko_ime=n.korisnicko_ime |
44 | | join dostavuvanja as dost on d.korisnicko_ime=dost.korisnicko_ime |
45 | | |
46 | | |
47 | | group by d.korisnicko_ime,n.korisnicko_ime; |
48 | | |
49 | | select vbn.korisnicko_ime,vbn.e_posta, vbn.broj_naracki as first |
50 | | from vkupen_broj_naracki as vbn |
51 | | where vbn.broj_naracki = (select max(broj_naracki) from vkupen_broj_naracki); |
52 | | |
53 | | select d.id_dostavuvanja ,d.korisnicko_ime , data_na_dostavuvanje as vreme_na_dostava, |
54 | | n.suma as suma_na_proizvod, g.datum_od as garancija |
55 | | |
56 | | from dostavuvanja d |
57 | | left join naracki n on d.id_naracka =n.id_naracka and n.suma > 2000 |
58 | | left join parce p on p.id_parce=n.id_naracka |
59 | | left join proizvodi p2 on p.id_proizvod=p2.id_proizvod |
60 | | left join garancija g on g.id_proizvod=p2.id_proizvod |
61 | | where |
62 | | data_na_dostavuvanje between data_na_naracka and data_na_naracka + interval '1 month' |
63 | | and |
64 | | now() between g.datum_od and g.datum_do |
| 38 | select d.korisnicko_ime, |
| 39 | max(na.suma) as najdobra_naracka, broj.broj_naracki as broj_naracki,max(najgolema_garancija.garan) as najgolema_garancija |
| 40 | from dostavuvaci d |
| 41 | left join |
| 42 | ( |
| 43 | select distinct d.korisnicko_ime as dostavuvac,k.e_posta as email, d2.id_dostavuvanja as broj_dostava |
| 44 | ,n.suma |
| 45 | from dostavuvaci d |
| 46 | left join korisnici k on k.korisnicko_ime=d.korisnicko_ime |
| 47 | left join dostavuvanja d2 on d2.korisnicko_ime = d.korisnicko_ime |
| 48 | left join naracki n on n.id_naracka =d2.id_naracka |
| 49 | left join parce_e_del_od_naracki pedon on pedon.id_naracka =n.id_naracka |
| 50 | left join parce p3 on p3.id_parce=pedon.id_parce |
| 51 | left join proizvodi p4 on p4.id_proizvod=p3.id_proizvod |
| 52 | left join cena c on c.id_proizvod=p4.id_proizvod |
| 53 | |
| 54 | ) as na on d.korisnicko_ime = na.dostavuvac |
| 55 | left join |
| 56 | ( |
| 57 | select d.korisnicko_ime,n.e_posta,count(dost.id_dostavuvanja) as broj_naracki |
| 58 | from dostavuvaci as d |
| 59 | join korisnici as n on d.korisnicko_ime=n.korisnicko_ime |
| 60 | join dostavuvanja as dost on d.korisnicko_ime=dost.korisnicko_ime |
| 61 | group by d.korisnicko_ime,n.korisnicko_ime |
| 62 | ) |
| 63 | as broj on d.korisnicko_ime = broj.korisnicko_ime |
| 64 | |
| 65 | left join |
| 66 | ( |
| 67 | select d.korisnicko_ime as dostavuvac,(g.datum_do-g.datum_od) as garan |
| 68 | from dostavuvaci d |
| 69 | left join dostavuvanja d2 on d2.korisnicko_ime = d.korisnicko_ime |
| 70 | left join naracki n on n.id_naracka =d2.id_naracka |
| 71 | left join parce_e_del_od_naracki pedon on pedon.id_naracka =n.id_naracka |
| 72 | left join parce p3 on p3.id_parce=pedon.id_parce |
| 73 | left join proizvodi p4 on p4.id_proizvod=p3.id_proizvod |
| 74 | left join garancija g on g.id_proizvod =p4.id_proizvod |
| 75 | ) as najgolema_garancija on najgolema_garancija.dostavuvac=d.korisnicko_ime |
| 76 | |
| 77 | |
| 78 | group by d.korisnicko_ime,broj.broj_naracki |
| 79 | order by najdobra_naracka desc |