Changes between Version 7 and Version 8 of AdvancedReports


Ignore:
Timestamp:
12/28/22 15:02:52 (2 years ago)
Author:
201084
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v7 v8  
    11= Напредни извештаи од базата (SQL и складирани процедури) =
    22
    3 === Извештај за сите сервиси,број на критики кои ги добиле и нивниот просечен рејтинг ===
    4 {{{#!sql
    5 select rs.id_repair_shop as rs_id , rs.rs_name as rs_name , count(r2.review_rating) as review_count ,avg(r2.review_rating)::float as review_average
    6 from project.repair_shop rs
    7 left join project.repair r on r.id_repair_shop = rs.id_repair_shop
    8 left join project.review r2 on r2.id_repair = r.id_repair
    9 group by rs.id_repair_shop
     3=== Извештај за сите делови, со нивни категории и производители, и количината која била нарачана од овие делови во секој од последните 3 календарски месеци. ===
     4
     5{{{#!sql
     6select p.id_part, p.part_name, cat.category_name, pm.pm_name,
     7coalesce (f.narachani_vo_ovoj_mesec,0) as narachani_ovoj_mesec,
     8coalesce (s.narachani_vo_prethoden_mesec,0) as narachani_prethoden_mesec,
     9coalesce (t.narachani_vo_predprethoden_mesec,0) as narachani_predprethoden_mesec
     10from project.part as p
     11join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
     12join project.part_is_from_category as pifc on p.id_part = pifc.id_part
     13join project.category as cat on pifc.id_category = cat.id_category
     14join project.order_contains_part as ocp on p.id_part = ocp.id_part
     15join project.order_table as o on ocp.id_order = o.id_order
     16left join (
     17select p.id_part, p.part_name, cat.category_name, pm.pm_name,
     18       sum(ocp.quantity_order) as narachani_vo_ovoj_mesec
     19from project.part as p
     20join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
     21join project.part_is_from_category as pifc on p.id_part = pifc.id_part
     22join project.category as cat on pifc.id_category = cat.id_category
     23join project.order_contains_part as ocp on p.id_part = ocp.id_part
     24join project.order_table as o on ocp.id_order = o.id_order
     25                                  and
     26                              extract(month from o.order_date) = extract(month from now()) and extract(year from o.order_date) = extract(year from now())
     27group by p.id_part, p.part_name, cat.category_name, pm.pm_name
     28) as f on p.id_part = f.id_part and pm.pm_name = f.pm_name
     29left join (
     30select p.id_part, p.part_name, cat.category_name, pm.pm_name,
     31       sum(ocp.quantity_order)  as narachani_vo_prethoden_mesec
     32from project.part as p
     33join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
     34join project.part_is_from_category as pifc on p.id_part = pifc.id_part
     35join project.category as cat on pifc.id_category = cat.id_category
     36join project.order_contains_part as ocp on p.id_part = ocp.id_part
     37join project.order_table as o on ocp.id_order = o.id_order
     38                                  and
     39                              extract(month from o.order_date) = extract(month from now()-interval'1 month') and extract(year from o.order_date) = extract(year from now()-interval'1 month')
     40group by p.id_part, p.part_name, cat.category_name, pm.pm_name
     41) as s on p.id_part = s.id_part and pm.pm_name = s.pm_name
     42left join (
     43select p.id_part, p.part_name, cat.category_name, pm.pm_name,
     44       sum(ocp.quantity_order)  as narachani_vo_predprethoden_mesec
     45from project.part as p
     46join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
     47join project.part_is_from_category as pifc on p.id_part = pifc.id_part
     48join project.category as cat on pifc.id_category = cat.id_category
     49join project.order_contains_part as ocp on p.id_part = ocp.id_part
     50join project.order_table as o on ocp.id_order = o.id_order
     51                                  and
     52                              extract(month from o.order_date) = extract(month from now()-interval'2 month') and extract(year from o.order_date) = extract(year from now()-interval'2 month')
     53group by p.id_part, p.part_name, cat.category_name, pm.pm_name
     54) as t on p.id_part = t.id_part and pm.pm_name = t.pm_name
     55group by p.id_part, p.part_name, cat.category_name, pm.pm_name, f.narachani_vo_ovoj_mesec, s.narachani_vo_prethoden_mesec, t.narachani_vo_predprethoden_mesec
     56}}}
     57
     58=== Извештај за производителите на авто делови, колку делови од тој производител се продаваат за секоја четвртина од годината ===
     59
     60{{{#!sql
     61select pm.id_part_manufacturer ,pm.pm_name ,
     62coalesce(fq.count_first_quarter,0) as first_quarter, coalesce(sq.count_second_quarter,0) as second_quarter,
     63coalesce(tq.count_third_quarter,0) as third_quarter, coalesce(frq.count_fourth_quarter,0) as fourth_quarter
     64from project.part_manufacturer pm
     65join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
     66join project.order_contains_part ocp on ocp.id_part = p.id_part
     67join project.order_table ot on ot.id_order = ocp.id_order
     68left join (
     69select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_first_quarter
     70from project.part_manufacturer pm
     71join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
     72join project.order_contains_part ocp on ocp.id_part = p.id_part
     73join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-01-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('31-03-',extract(year from now())),'dd-mm-yyyy')
     74group by pm.id_part_manufacturer
     75) as fq on pm.id_part_manufacturer = fq.id_part_manufacturer and pm.pm_name = fq.pm_name
     76left join (
     77select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_second_quarter
     78from project.part_manufacturer pm
     79join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
     80join project.order_contains_part ocp on ocp.id_part = p.id_part
     81join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-04-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('30-06-',extract(year from now())),'dd-mm-yyyy')
     82group by pm.id_part_manufacturer
     83) as sq on pm.id_part_manufacturer = sq.id_part_manufacturer and pm.pm_name = sq.pm_name
     84left join (
     85select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_third_quarter
     86from project.part_manufacturer pm
     87join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
     88join project.order_contains_part ocp on ocp.id_part = p.id_part
     89join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-07-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('30-09-',extract(year from now())),'dd-mm-yyyy')
     90group by pm.id_part_manufacturer
     91) as tq on pm.id_part_manufacturer = tq.id_part_manufacturer and pm.pm_name = tq.pm_name
     92left join (
     93select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_fourth_quarter
     94from project.part_manufacturer pm
     95join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
     96join project.order_contains_part ocp on ocp.id_part = p.id_part
     97join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-10-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('31-12-',extract(year from now())),'dd-mm-yyyy')
     98group by pm.id_part_manufacturer
     99) as frq on pm.id_part_manufacturer = frq.id_part_manufacturer and pm.pm_name = frq.pm_name
     100group by pm.id_part_manufacturer, fq.count_first_quarter, sq.count_second_quarter, tq.count_third_quarter, frq.count_fourth_quarter
    10101}}}
    11102
     
    65156        order by vkupna_suma desc
    66157}}}
     158
    67159=== Извештај за сите категории и за кој прозиводител на коли биле купени највеќе делови од таа категорија ===
     160
    68161{{{#!sql
    69162select c.id_category, c.category_name, cm.id_car_manufacturer , cm.cm_name ,
     
    83176
    84177=== Извештај за најкупуван артикл, во која количина и од која категорија е истиот ===
     178
    85179{{{#!sql
    86180select c.category_name , p.part_name , coalesce(sum(ocp2.quantity_order),0) as maxkol from project.part p
     
    101195}}}
    102196
    103 === Извештај за сите делови, со нивни категории и производители, и количината која била нарачана од овие делови во секој од последните 3 календарски месеци. ===
    104 {{{#!sql
    105 select p.id_part, p.part_name, cat.category_name, pm.pm_name,
    106 coalesce (f.narachani_vo_ovoj_mesec,0) as narachani_ovoj_mesec,
    107 coalesce (s.narachani_vo_prethoden_mesec,0) as narachani_prethoden_mesec,
    108 coalesce (t.narachani_vo_predprethoden_mesec,0) as narachani_predprethoden_mesec
    109 from project.part as p
    110 join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
    111 join project.part_is_from_category as pifc on p.id_part = pifc.id_part
    112 join project.category as cat on pifc.id_category = cat.id_category
    113 join project.order_contains_part as ocp on p.id_part = ocp.id_part
    114 join project.order_table as o on ocp.id_order = o.id_order
    115 left join (
    116 select p.id_part, p.part_name, cat.category_name, pm.pm_name,
    117        sum(ocp.quantity_order) as narachani_vo_ovoj_mesec
    118 from project.part as p
    119 join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
    120 join project.part_is_from_category as pifc on p.id_part = pifc.id_part
    121 join project.category as cat on pifc.id_category = cat.id_category
    122 join project.order_contains_part as ocp on p.id_part = ocp.id_part
    123 join project.order_table as o on ocp.id_order = o.id_order
    124                                   and
    125                               extract(month from o.order_date) = extract(month from now()) and extract(year from o.order_date) = extract(year from now())
    126 group by p.id_part, p.part_name, cat.category_name, pm.pm_name
    127 ) as f on p.id_part = f.id_part and pm.pm_name = f.pm_name
    128 left join (
    129 select p.id_part, p.part_name, cat.category_name, pm.pm_name,
    130        sum(ocp.quantity_order)  as narachani_vo_prethoden_mesec
    131 from project.part as p
    132 join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
    133 join project.part_is_from_category as pifc on p.id_part = pifc.id_part
    134 join project.category as cat on pifc.id_category = cat.id_category
    135 join project.order_contains_part as ocp on p.id_part = ocp.id_part
    136 join project.order_table as o on ocp.id_order = o.id_order
    137                                   and
    138                               extract(month from o.order_date) = extract(month from now()-interval'1 month') and extract(year from o.order_date) = extract(year from now()-interval'1 month')
    139 group by p.id_part, p.part_name, cat.category_name, pm.pm_name
    140 ) as s on p.id_part = s.id_part and pm.pm_name = s.pm_name
    141 left join (
    142 select p.id_part, p.part_name, cat.category_name, pm.pm_name,
    143        sum(ocp.quantity_order)  as narachani_vo_predprethoden_mesec
    144 from project.part as p
    145 join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer
    146 join project.part_is_from_category as pifc on p.id_part = pifc.id_part
    147 join project.category as cat on pifc.id_category = cat.id_category
    148 join project.order_contains_part as ocp on p.id_part = ocp.id_part
    149 join project.order_table as o on ocp.id_order = o.id_order
    150                                   and
    151                               extract(month from o.order_date) = extract(month from now()-interval'2 month') and extract(year from o.order_date) = extract(year from now()-interval'2 month')
    152 group by p.id_part, p.part_name, cat.category_name, pm.pm_name
    153 ) as t on p.id_part = t.id_part and pm.pm_name = t.pm_name
    154 group by p.id_part, p.part_name, cat.category_name, pm.pm_name, f.narachani_vo_ovoj_mesec, s.narachani_vo_prethoden_mesec, t.narachani_vo_predprethoden_mesec
    155 
    156 }}}
    157197=== Извештај за деловите кои биле нарачани во последните 3 месеци, со нивни категории и производители и количината која била нарачана ===
     198
    158199{{{#!sql
    159200select p.id_part, p.part_name, cat.category_name, pm.pm_name,
     
    170211}}}
    171212
    172 === Извештај за производителите на авто делови, колку делови од тој производител се продаваат за секоја четвртина од годината ===
    173 {{{#!sql
    174 select pm.id_part_manufacturer ,pm.pm_name ,
    175 coalesce(fq.count_first_quarter,0) as first_quarter, coalesce(sq.count_second_quarter,0) as second_quarter,
    176 coalesce(tq.count_third_quarter,0) as third_quarter, coalesce(frq.count_fourth_quarter,0) as fourth_quarter
    177 from project.part_manufacturer pm
    178 join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
    179 join project.order_contains_part ocp on ocp.id_part = p.id_part
    180 join project.order_table ot on ot.id_order = ocp.id_order
    181 left join (
    182 select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_first_quarter
    183 from project.part_manufacturer pm
    184 join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
    185 join project.order_contains_part ocp on ocp.id_part = p.id_part
    186 join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-01-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('31-03-',extract(year from now())),'dd-mm-yyyy')
    187 group by pm.id_part_manufacturer
    188 ) as fq on pm.id_part_manufacturer = fq.id_part_manufacturer and pm.pm_name = fq.pm_name
    189 left join (
    190 select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_second_quarter
    191 from project.part_manufacturer pm
    192 join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
    193 join project.order_contains_part ocp on ocp.id_part = p.id_part
    194 join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-04-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('30-06-',extract(year from now())),'dd-mm-yyyy')
    195 group by pm.id_part_manufacturer
    196 ) as sq on pm.id_part_manufacturer = sq.id_part_manufacturer and pm.pm_name = sq.pm_name
    197 left join (
    198 select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_third_quarter
    199 from project.part_manufacturer pm
    200 join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
    201 join project.order_contains_part ocp on ocp.id_part = p.id_part
    202 join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-07-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('30-09-',extract(year from now())),'dd-mm-yyyy')
    203 group by pm.id_part_manufacturer
    204 ) as tq on pm.id_part_manufacturer = tq.id_part_manufacturer and pm.pm_name = tq.pm_name
    205 left join (
    206 select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_fourth_quarter
    207 from project.part_manufacturer pm
    208 join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer
    209 join project.order_contains_part ocp on ocp.id_part = p.id_part
    210 join project.order_table ot on ot.id_order = ocp.id_order and ot.order_date between to_date(concat('01-10-',extract(year from now())),'dd-mm-yyyy') and to_date(concat('31-12-',extract(year from now())),'dd-mm-yyyy')
    211 group by pm.id_part_manufacturer
    212 ) as frq on pm.id_part_manufacturer = frq.id_part_manufacturer and pm.pm_name = frq.pm_name
    213 group by pm.id_part_manufacturer, fq.count_first_quarter, sq.count_second_quarter, tq.count_third_quarter, frq.count_fourth_quarter
    214 
    215 }}}
     213=== Извештај за сите сервиси,број на критики кои ги добиле и нивниот просечен рејтинг ===
     214
     215{{{#!sql
     216select rs.id_repair_shop as rs_id , rs.rs_name as rs_name , count(r2.review_rating) as review_count ,avg(r2.review_rating)::float as review_average
     217from project.repair_shop rs
     218left join project.repair r on r.id_repair_shop = rs.id_repair_shop
     219left join project.review r2 on r2.id_repair = r.id_repair
     220group by rs.id_repair_shop
     221}}}
     222