| | 1 | = Материјализирани погледи = |
| | 2 | === Статистика на случаи по полициска станица === |
| | 3 | |
| | 4 | {{{#!div |
| | 5 | {{{#!sql |
| | 6 | create materialized view case_statistics_by_station as |
| | 7 | select |
| | 8 | ps.p_id, |
| | 9 | ps.p_address as station_address, |
| | 10 | sia.city, |
| | 11 | count(cc.c_id) as total_cases, |
| | 12 | count(case when cc.c_status = 'A' then 1 end) as active_cases, |
| | 13 | count(CASE when cc.c_status = 'Z' then 1 end) as closed_cases, |
| | 14 | count(sc.c_id) as solved_cases |
| | 15 | from Police_station as ps |
| | 16 | left join Crime_case as cc on ps.p_id = cc.p_id |
| | 17 | left join Solved_case as sc on cc.c_id = sc.c_id |
| | 18 | left join Sector_of_interal_affairs as sia on ps.s_id = sia.s_id |
| | 19 | group by ps.p_id, ps.p_address, sia.city; |
| | 20 | }}} |
| | 21 | }}} |
| | 22 | |
| | 23 | === Анализа на типови на криминал === |
| | 24 | |
| | 25 | {{{#!div |
| | 26 | {{{#!sql |
| | 27 | create materialized view crime_type_analysis as |
| | 28 | select |
| | 29 | tc.t_id, |
| | 30 | tc.t_name, |
| | 31 | count(cbtc.c_id) as total_cases, |
| | 32 | count(sc.c_id) as solved_cases, |
| | 33 | count(distinct af.accused_pe_id) as total_accused |
| | 34 | from Type_of_crime as tc |
| | 35 | left join Case_belongs_to_type_of_crime as cbtc on tc.t_id = cbtc.t_id |
| | 36 | left join Crime_case as cc on cbtc.c_id = cc.c_id |
| | 37 | left join Solved_case as sc on cc.c_id = sc.c_id |
| | 38 | left join Accused_for as af on cc.c_id = af.c_id |
| | 39 | group by tc.t_id, tc.t_name; |
| | 40 | }}} |
| | 41 | }}} |
| | 42 | |
| | 43 | === Анализа на перформансот на секој службеник === |
| | 44 | |
| | 45 | {{{#!div |
| | 46 | {{{#!sql |
| | 47 | create materialized view police_performance as |
| | 48 | select |
| | 49 | 'Officer' as role_type, |
| | 50 | o.pe_id, |
| | 51 | p.first_name, |
| | 52 | p.last_name, |
| | 53 | o.o_badge_no as badge_number, |
| | 54 | o.o_date_of_employment as date_of_employment, |
| | 55 | ps.p_address as station_address, |
| | 56 | count(distinct cc.c_id) as cases_managed |
| | 57 | from Officer as o |
| | 58 | join People as p on o.pe_id = p.pe_id |
| | 59 | left join Police_station ps on o.pe_id = ps.pe_id |
| | 60 | left join Crime_case cc on ps.p_id = cc.p_id |
| | 61 | group by o.pe_id, p.first_name, p.last_name, o.o_badge_no, o.o_date_of_employment, ps.p_address |
| | 62 | |
| | 63 | union all |
| | 64 | |
| | 65 | select |
| | 66 | 'Policeman' as role_type, |
| | 67 | pm.pe_id, |
| | 68 | p.first_name, |
| | 69 | p.last_name, |
| | 70 | pm.badge_no as badge_number, |
| | 71 | pm.p_date_of_employment as date_of_employment, |
| | 72 | ps.p_address as station_address, |
| | 73 | count(distinct s.c_id) as cases_handled |
| | 74 | from Policeman as pm |
| | 75 | join People as p on pm.pe_id = p.pe_id |
| | 76 | left join Police_station as ps on pm.p_id = ps.p_id |
| | 77 | left join Statements as s on pm.pe_id = s.pe_id |
| | 78 | group by pm.pe_id, p.first_name, p.last_name, pm.badge_no, pm.p_date_of_employment, ps.p_address; |
| | 79 | }}} |
| | 80 | }}} |
| | 81 | |
| | 82 | === Сумирање на типови на докази === |
| | 83 | |
| | 84 | {{{#!div |
| | 85 | {{{#!sql |
| | 86 | create materialized view evidence_summary as |
| | 87 | select |
| | 88 | e.e_type, |
| | 89 | count(*) as total_evidence, |
| | 90 | count(case when e.is_found = true then 1 end) as found_evidence, |
| | 91 | count(case when e.is_found = false then 1 end) as missing_evidence |
| | 92 | from Evidence as e |
| | 93 | group by e.e_type; |
| | 94 | }}} |
| | 95 | }}} |
| | 96 | |
| | 97 | {{{#!div |
| | 98 | {{{#!sql |
| | 99 | }}} |
| | 100 | }}} |