75 | | |
| 75 | == Секој ветеринарен центар колку вкупно миленичиња примил и колку е просечната возраст во секој ветеринарен центар. |
| 76 | {{{ |
| 77 | SELECT |
| 78 | vc.name AS vet_center_name, |
| 79 | -- vc.description AS vet_center_description, |
| 80 | COUNT(DISTINCT pvvc.id_pets) AS number_of_pets_treated, |
| 81 | AVG(EXTRACT(YEAR FROM age(current_date, p.dateofbirthday))) AS average_pet_age |
| 82 | FROM |
| 83 | project.vet_centers vc |
| 84 | JOIN |
| 85 | project.pets_visit_vet_centers pvvc ON vc.id = pvvc.id_vet_centers |
| 86 | JOIN |
| 87 | project.pets p ON pvvc.id_pets = p.id |
| 88 | GROUP BY |
| 89 | vc.id, vc.name, vc.description |
| 90 | ORDER BY |
| 91 | number_of_pets_treated DESC; |
| 92 | }}} |