157 | | select p.ime as predmet, count(pp.id_nastavnik) broj_na_nastavnici |
158 | | from predmeti p |
159 | | join predava_predmet pp on pp.id_predmet = p.id_predmet |
160 | | group by p.id_predmet |
161 | | order by p.ime; |
| 157 | select q4."name", q4.surname, q4.max_broj_nastani |
| 158 | from |
| 159 | ( |
| 160 | |
| 161 | (select u."name", u.surname, count(e.id_event) as broj_nastani |
| 162 | from artist a join users u on a.id_user =u.id_user |
| 163 | join events e on a.id_user =e.id_user_artist |
| 164 | group by u."name", u.surname) q1 |
| 165 | |
| 166 | join |
| 167 | |
| 168 | (select max(q2.broj_nastani) as max_broj_nastani |
| 169 | from (select u."name", u.surname, count(e.id_event) as broj_nastani |
| 170 | from artist a join users u on a.id_user =u.id_user |
| 171 | join events e on a.id_user =e.id_user_artist |
| 172 | group by u."name", u.surname |
| 173 | ) q2 ) q3 |
| 174 | on q1.broj_nastani=q3.max_broj_nastani) |
| 175 | |
| 176 | as q4 |