92 | | ) upati_quarter on (o.oddel_id, o.bolnica_id) = (upati_quarter.oddel_id, upati_quarter.bolnica_id) |
| 92 | ) upati_quarter on (o.oddel_id, o.bolnica_id) = (upati_quarter.oddel_id, upati_quarter.bolnica_id) ; |
| 93 | }}} |
| 94 | |
| 95 | |
| 96 | |
| 97 | == Тренд на препишани лекови по тримесечја за тековната година |
| 98 | |
| 99 | {{{#!sql |
| 100 | select distinct l.ime_lek, |
| 101 | case when recepta_quarter.trimesecje = 1 then recepti_za_lekovi.recepti_za_lek else 0 end as quarter_1_recepti_za_lek, |
| 102 | case when recepta_quarter.trimesecje = 2 then recepti_za_lekovi.recepti_za_lek else 0 end as quarter_2_recepti_za_lek, |
| 103 | case when recepta_quarter.trimesecje = 3 then recepti_za_lekovi.recepti_za_lek else 0 end as quarter_3_recepti_za_lek, |
| 104 | case when recepta_quarter.trimesecje = 4 then recepti_za_lekovi.recepti_za_lek else 0 end as quarter_4_recepti_za_lek |
| 105 | from recepta r |
| 106 | join lekovi l on r.lek_id = l.lek_id |
| 107 | join ( |
| 108 | select r.recepta_id, extract (quarter from r.datum_izdavanje) as trimesecje |
| 109 | from recepta r |
| 110 | ) recepta_quarter on r.recepta_id = recepta_quarter.recepta_id |
| 111 | join ( |
| 112 | select r.lek_id, count(r.recepta_id) as recepti_za_lek |
| 113 | from recepta r |
| 114 | where extract (year from r.datum_izdavanje) = extract (year from current_date) |
| 115 | group by 1 |
| 116 | ) recepti_za_lekovi on r.lek_id = recepti_za_lekovi.lek_id |
| 117 | order by 2 desc, 3 desc, 4 desc, 5 desc ; |