| 4 | {{{#!sql |
| 5 | create view vkupen_broj_naracki as |
| 6 | |
| 7 | select d.korisnicko_ime,n.korisnicko_ime,n.email,count(dost.id_dostavuvanja) as broj_naracki |
| 8 | from dostavuvaci as d |
| 9 | join korisnici as n on d.korisnicko_ime=n.korisnicko_ime |
| 10 | join dostavuvanja as dost on d.korisnicko_ime=dost.korisnicko_ime |
| 11 | |
| 12 | |
| 13 | group by 1, 2, 3; |
| 14 | |
| 15 | select vbn.korisnicko_ime,vbn.email, vbn.broj_naracki as first |
| 16 | from vkupen_broj_naracki as vbn |
| 17 | where vbn.broj_naracki = (select max(broj_naracki) from vkupen_broj_naracki); |
| 18 | |
| 19 | }}} |
| 22 | {{{#!sql |
| 23 | drop view if exists produkti_cena; |
| 24 | |
| 25 | create view produkti_cena as |
| 26 | |
| 27 | select p.ime, p.kolicina, m.lokacija, c.iznos |
| 28 | from proizvodi as p |
| 29 | left join parce as pr on pr.id_proizvod=p.id_proizvod |
| 30 | left join parce_dostapno_vo_magacini as pdm on pr.id_parce=pdm.id_parce |
| 31 | left join magacini as m on pdm.id_magacin=pdm.id_magacin |
| 32 | left join cena as c on c.id_proizvod=p.id_proizvod |
| 33 | |
| 34 | group by 1, 2, 3, 4; |
| 35 | |
| 36 | select pc.ime, pc.kolicina, pc.lokacija, pc.iznos as najniska_cena |
| 37 | from produkti_cena as pc |
| 38 | where pc.iznos = (select min(iznos) from produkti_cena) |
| 39 | }}} |