Changes between Version 37 and Version 38 of AdvancedReports


Ignore:
Timestamp:
07/22/24 14:57:49 (2 months ago)
Author:
184006
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v37 v38  
    309309  avg_sales_quantity DESC;
    310310}}}
     311=== За секој миленик кој болести се дијагностицирани, какви лекови и терапија е препишена.
     312{{{
     313WITH 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),
     325PetMedications 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),
     339PetTherapy 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
     352SELECT
     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
     360FROM
     361    PetDiagnosis pd
     362LEFT JOIN
     363    PetMedications pm ON pd.pet_id = pm.pet_id
     364LEFT JOIN
     365    PetTherapy pt ON pd.pet_id = pt.pet_id
     366ORDER BY
     367    pd.pet_id, pt.therapy_date;
     368
     369}}}