208 | | a.id_user, |
209 | | a.verified_by_employee, |
210 | | count(distinct a2.id_adoption) as number_of_adoptions |
211 | | from adopter a |
212 | | join adoption a2 on a.id_user = a2.id_adopter |
213 | | group by a.id_user |
214 | | ) q1 |
215 | | join employee e on e.id_user = q1.verified_by_employee |
216 | | group by e.id_user |
217 | | order by e.id_user asc |
| 210 | e.id_user, |
| 211 | e.id_shelter, |
| 212 | count(distinct q1.id_user) as verified_adopters, |
| 213 | sum(q1.number_of_adoptions) as number_of_adoptions_under_employee |
| 214 | from |
| 215 | ( |
| 216 | select |
| 217 | a.id_user, |
| 218 | a.verified_by_employee, |
| 219 | count(distinct a2.id_adoption) as number_of_adoptions |
| 220 | from adopter a |
| 221 | join adoption a2 on a.id_user = a2.id_adopter |
| 222 | group by a.id_user |
| 223 | ) q1 |
| 224 | join employee e on e.id_user = q1.verified_by_employee |
| 225 | group by e.id_user |
| 226 | order by e.id_user asc |
| 227 | ) q2 on s.id_shelter = q2.id_shelter |
| 228 | join ( |
| 229 | select |
| 230 | s.id_shelter, |
| 231 | count(distinct e2.id_user) as number_of_employees |
| 232 | from shelter s |
| 233 | join employee e2 on e2.id_shelter = s.id_shelter |
| 234 | group by s.id_shelter |
| 235 | ) q3 on q3.id_shelter = s.id_shelter |
| 236 | group by s.id_shelter, q2.id_shelter, q3.number_of_employees,q2.verified_adopters, q2.number_of_adoptions_under_employee |
| 237 | order by s.id_shelter |