6 | | --sql here |
| 6 | select |
| 7 | ut.name_user as posvojuvac, |
| 8 | count(distinct pm.id_pet) as broj_posvoeni_macki, |
| 9 | count(distinct pd.id_pet) as broj_posvoeni_kucinja, |
| 10 | count(distinct pp.id_pet) as broj_posvoeni_ptici, |
| 11 | count(distinct p.id_pet) as vkupno_posvoeni_milenici |
| 12 | from |
| 13 | adopter a |
| 14 | join |
| 15 | user_table ut on a.id_user = ut.id_user |
| 16 | left join |
| 17 | adoption ad on ad.id_adopter = a.id_user |
| 18 | left join |
| 19 | pet pm on pm.id_adoption = ad.id_adoption |
| 20 | and |
| 21 | pm.species = 0 |
| 22 | left join |
| 23 | pet pd on pd.id_adoption = ad.id_adoption |
| 24 | and |
| 25 | pd.species = 1 |
| 26 | left join |
| 27 | pet pp on pp.id_adoption = ad.id_adoption |
| 28 | and |
| 29 | pp.species = 2 |
| 30 | left join |
| 31 | pet p on p.id_adoption = ad.id_adoption |
| 32 | group by |
| 33 | a.id_user, ut.name_user |
| 34 | order by |
| 35 | vkupno_posvoeni_milenici desc |