| 50 | | (text here) |
| 51 | | {{{#!sql |
| 52 | | --sql here |
| | 50 | За секое посвојување, идентификациски број, почетен и краен датум и статус. За посвојувачот се прикажуваат името, електронската пошта и телефонскиот број. За посвојувањето се пресметуваат број на миленици, број на различни видови (мачки, кучиња, птици) и севкупен број на терапии и интервенции потребни на сите миленици. |
| | 51 | {{{#!sql |
| | 52 | select |
| | 53 | q2.id_adoption as id, |
| | 54 | q2.start_date, |
| | 55 | q2.end_date_foster, |
| | 56 | q2.status, |
| | 57 | user_table.name_user as adopter_name, |
| | 58 | user_table.email_user as adopter_email, |
| | 59 | user_table.telephone_user as adopter_phone, |
| | 60 | q2.number_of_pets, |
| | 61 | q2.number_of_species, |
| | 62 | q2.total_therapies, |
| | 63 | q2.total_interventions |
| | 64 | from |
| | 65 | ( |
| | 66 | select |
| | 67 | adoption.id_adoption, |
| | 68 | adoption.start_date, |
| | 69 | adoption.end_date_foster, |
| | 70 | case |
| | 71 | when adoption.approved = false then 'under review' |
| | 72 | when adoption.approved = true then 'approved' |
| | 73 | end |
| | 74 | as status, |
| | 75 | count(distinct q1.id_pet) as number_of_pets, |
| | 76 | count(distinct q1.species) as number_of_species, |
| | 77 | sum(q1.therapies) as total_therapies, |
| | 78 | sum(q1.interventions) as total_interventions |
| | 79 | from |
| | 80 | ( |
| | 81 | select |
| | 82 | pet.id_pet, |
| | 83 | pet.name_pet, |
| | 84 | pet.id_adoption, |
| | 85 | pet.species, |
| | 86 | count(distinct pnt.id_therapy) as therapies, |
| | 87 | count(distinct description) as interventions |
| | 88 | from |
| | 89 | pet |
| | 90 | left join |
| | 91 | pet_needs_therapy pnt |
| | 92 | on pnt.id_pet = pet.id_pet |
| | 93 | left join |
| | 94 | pet_needs_intervention_in_vet_clinic pni |
| | 95 | on pni.id_pet = pet.id_pet |
| | 96 | group by |
| | 97 | pet.id_pet |
| | 98 | ) as q1 |
| | 99 | right join |
| | 100 | adoption |
| | 101 | on q1.id_adoption = adoption.id_adoption |
| | 102 | group by |
| | 103 | adoption.id_adoption |
| | 104 | ) as q2 |
| | 105 | left join |
| | 106 | adoption |
| | 107 | on adoption.id_adoption = q2.id_adoption |
| | 108 | left join |
| | 109 | adopter |
| | 110 | on adopter.id_user = adoption.id_adopter |
| | 111 | left join |
| | 112 | user_table |
| | 113 | on user_table.id_user = adopter.id_user |