159 | | (text here) |
160 | | {{{#!sql |
161 | | --sql here |
| 159 | За секој посвојувач, вкупен број на миленици од прифатилиште и вкупен број на миленици огласени од граѓани. За посвојувачите се прикажуваат име презиме и контакт информации (електронска пошта и телефон). |
| 160 | {{{#!sql |
| 161 | select |
| 162 | q3.id_user, |
| 163 | user_table.name_user, |
| 164 | user_table.email_user, |
| 165 | user_table.telephone_user, |
| 166 | q3.pets_from_surendee, |
| 167 | q3.pets_from_shelter |
| 168 | from |
| 169 | ( |
| 170 | select |
| 171 | adopter.id_user, |
| 172 | sum(q1.surendee_count) as pets_from_surendee, |
| 173 | sUm(q2.shelter_count) as pets_from_shelter |
| 174 | from |
| 175 | adopter |
| 176 | left join |
| 177 | ( |
| 178 | select |
| 179 | adoption.id_adoption, |
| 180 | adoption.id_adopter, |
| 181 | count(surendee.id_user) as surendee_count |
| 182 | from |
| 183 | adoption |
| 184 | left join |
| 185 | pet |
| 186 | on pet.id_adoption = adoption.id_adoption |
| 187 | left join |
| 188 | post |
| 189 | on post.id_pet = pet.id_pet |
| 190 | left join |
| 191 | surendee |
| 192 | on surendee.id_user = post.id_surendee |
| 193 | group by |
| 194 | adoption.id_adoption |
| 195 | ) as q1 |
| 196 | on q1.id_adopter = adopter.id_user |
| 197 | left join |
| 198 | ( |
| 199 | select |
| 200 | adoption.id_adoption, |
| 201 | adoption.id_adopter, |
| 202 | count(employee.id_user) as shelter_count |
| 203 | from |
| 204 | adoption |
| 205 | left join |
| 206 | pet |
| 207 | on pet.id_adoption = adoption.id_adoption |
| 208 | left join |
| 209 | post |
| 210 | on post.id_pet = pet.id_pet |
| 211 | left join |
| 212 | employee |
| 213 | on employee.id_user = post.id_employee |
| 214 | group by |
| 215 | adoption.id_adoption |
| 216 | ) as q2 |
| 217 | on q2.id_adopter = adopter.id_user |
| 218 | group by |
| 219 | adopter.id_user |
| 220 | order by |
| 221 | adopter.id_user |
| 222 | ) as q3 |
| 223 | left join |
| 224 | user_table |
| 225 | on user_table.id_user = q3.id_user |