| 311 | === За секој миленик кој болести се дијагностицирани, какви лекови и терапија е препишена. |
| 312 | {{{ |
| 313 | WITH PetDiagnosis AS ( |
| 314 | SELECT |
| 315 | p.id AS pet_id, |
| 316 | p.name AS pet_name, |
| 317 | d.description AS diagnosis_description |
| 318 | FROM |
| 319 | pets p |
| 320 | JOIN |
| 321 | diagnostics_established_pets dep ON p.id = dep.id_pets |
| 322 | JOIN |
| 323 | diagnostics d ON dep.id_diagnostics = d.id |
| 324 | ), |
| 325 | PetMedications AS ( |
| 326 | SELECT |
| 327 | p.id AS pet_id, |
| 328 | m.name AS medicine_name, |
| 329 | m.description AS medicine_description |
| 330 | FROM |
| 331 | pets p |
| 332 | JOIN |
| 333 | therapy_takes_pets ttp ON p.id = ttp.id_pets |
| 334 | JOIN |
| 335 | therapy t ON ttp.id_therapy = t.id |
| 336 | JOIN |
| 337 | medecines m ON t.diagnosticsID = m.diagnosticsID |
| 338 | ), |
| 339 | PetTherapy AS ( |
| 340 | SELECT |
| 341 | p.id AS pet_id, |
| 342 | t.description AS therapy_description, |
| 343 | t.appoitmentDate AS therapy_date |
| 344 | FROM |
| 345 | pets p |
| 346 | JOIN |
| 347 | therapy_takes_pets ttp ON p.id = ttp.id_pets |
| 348 | JOIN |
| 349 | therapy t ON ttp.id_therapy = t.id |
| 350 | ) |
| 351 | |
| 352 | SELECT |
| 353 | pd.pet_id, |
| 354 | pd.pet_name, |
| 355 | pd.diagnosis_description, |
| 356 | pm.medicine_name, |
| 357 | pm.medicine_description, |
| 358 | pt.therapy_description, |
| 359 | pt.therapy_date |
| 360 | FROM |
| 361 | PetDiagnosis pd |
| 362 | LEFT JOIN |
| 363 | PetMedications pm ON pd.pet_id = pm.pet_id |
| 364 | LEFT JOIN |
| 365 | PetTherapy pt ON pd.pet_id = pt.pet_id |
| 366 | ORDER BY |
| 367 | pd.pet_id, pt.therapy_date; |
| 368 | |
| 369 | }}} |