117 | | (text here) |
118 | | {{{#!sql |
119 | | --sql here |
| 117 | За секоја храна, бројот на миленици кои ја јадат таа храна кои имаат ниска физичка активност и примаат терапии. |
| 118 | {{{#!sql |
| 119 | select |
| 120 | food.name_food as food_name, |
| 121 | sum(q2.has_therapies) as total_pets |
| 122 | from |
| 123 | ( |
| 124 | select |
| 125 | q1.pet_id, |
| 126 | q1.has_therapies |
| 127 | from |
| 128 | ( |
| 129 | select |
| 130 | pet.id_pet as pet_id, |
| 131 | count(therapy.id_therapy) as has_therapies |
| 132 | from |
| 133 | pet |
| 134 | join |
| 135 | pet_needs_therapy pnt |
| 136 | on pnt.id_pet = pet.id_pet |
| 137 | join |
| 138 | therapy |
| 139 | on therapy.id_therapy = pnt.id_therapy |
| 140 | group by |
| 141 | pet.id_pet |
| 142 | ) as q1 |
| 143 | join personal_profile |
| 144 | on q1.pet_id = personal_profile.id_pet |
| 145 | where |
| 146 | personal_profile.physical_activity = 0 |
| 147 | ) as q2 |
| 148 | join pet_preferably_eats_food ppef |
| 149 | on ppef.id_pet = q2.pet_id |
| 150 | join food |
| 151 | on food.id_food = ppef.id_food |
| 152 | group by |
| 153 | food.id_food |
| 154 | order by |
| 155 | total_pets |