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 |
| 6 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 7 | coalesce (f.narachani_vo_ovoj_mesec,0) as narachani_ovoj_mesec, |
| 8 | coalesce (s.narachani_vo_prethoden_mesec,0) as narachani_prethoden_mesec, |
| 9 | coalesce (t.narachani_vo_predprethoden_mesec,0) as narachani_predprethoden_mesec |
| 10 | from project.part as p |
| 11 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 12 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 13 | join project.category as cat on pifc.id_category = cat.id_category |
| 14 | join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 15 | join project.order_table as o on ocp.id_order = o.id_order |
| 16 | left join ( |
| 17 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 18 | sum(ocp.quantity_order) as narachani_vo_ovoj_mesec |
| 19 | from project.part as p |
| 20 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 21 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 22 | join project.category as cat on pifc.id_category = cat.id_category |
| 23 | join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 24 | join 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()) |
| 27 | group 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 |
| 29 | left join ( |
| 30 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 31 | sum(ocp.quantity_order) as narachani_vo_prethoden_mesec |
| 32 | from project.part as p |
| 33 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 34 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 35 | join project.category as cat on pifc.id_category = cat.id_category |
| 36 | join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 37 | join 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') |
| 40 | group 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 |
| 42 | left join ( |
| 43 | select p.id_part, p.part_name, cat.category_name, pm.pm_name, |
| 44 | sum(ocp.quantity_order) as narachani_vo_predprethoden_mesec |
| 45 | from project.part as p |
| 46 | join project.part_manufacturer as pm on p.id_part_manufacturer = pm.id_part_manufacturer |
| 47 | join project.part_is_from_category as pifc on p.id_part = pifc.id_part |
| 48 | join project.category as cat on pifc.id_category = cat.id_category |
| 49 | join project.order_contains_part as ocp on p.id_part = ocp.id_part |
| 50 | join 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') |
| 53 | group 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 |
| 55 | 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 |
| 56 | }}} |
| 57 | |
| 58 | === Извештај за производителите на авто делови, колку делови од тој производител се продаваат за секоја четвртина од годината === |
| 59 | |
| 60 | {{{#!sql |
| 61 | select pm.id_part_manufacturer ,pm.pm_name , |
| 62 | coalesce(fq.count_first_quarter,0) as first_quarter, coalesce(sq.count_second_quarter,0) as second_quarter, |
| 63 | coalesce(tq.count_third_quarter,0) as third_quarter, coalesce(frq.count_fourth_quarter,0) as fourth_quarter |
| 64 | from project.part_manufacturer pm |
| 65 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 66 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 67 | join project.order_table ot on ot.id_order = ocp.id_order |
| 68 | left join ( |
| 69 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_first_quarter |
| 70 | from project.part_manufacturer pm |
| 71 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 72 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 73 | 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') |
| 74 | group by pm.id_part_manufacturer |
| 75 | ) as fq on pm.id_part_manufacturer = fq.id_part_manufacturer and pm.pm_name = fq.pm_name |
| 76 | left join ( |
| 77 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_second_quarter |
| 78 | from project.part_manufacturer pm |
| 79 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 80 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 81 | 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') |
| 82 | group by pm.id_part_manufacturer |
| 83 | ) as sq on pm.id_part_manufacturer = sq.id_part_manufacturer and pm.pm_name = sq.pm_name |
| 84 | left join ( |
| 85 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_third_quarter |
| 86 | from project.part_manufacturer pm |
| 87 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 88 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 89 | 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') |
| 90 | group by pm.id_part_manufacturer |
| 91 | ) as tq on pm.id_part_manufacturer = tq.id_part_manufacturer and pm.pm_name = tq.pm_name |
| 92 | left join ( |
| 93 | select pm.id_part_manufacturer ,pm.pm_name , count(ocp.id_part) as count_fourth_quarter |
| 94 | from project.part_manufacturer pm |
| 95 | join project.part p on p.id_part_manufacturer = pm.id_part_manufacturer |
| 96 | join project.order_contains_part ocp on ocp.id_part = p.id_part |
| 97 | 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') |
| 98 | group by pm.id_part_manufacturer |
| 99 | ) as frq on pm.id_part_manufacturer = frq.id_part_manufacturer and pm.pm_name = frq.pm_name |
| 100 | group by pm.id_part_manufacturer, fq.count_first_quarter, sq.count_second_quarter, tq.count_third_quarter, frq.count_fourth_quarter |
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 | | }}} |
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 |
| 216 | 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 |
| 217 | from project.repair_shop rs |
| 218 | left join project.repair r on r.id_repair_shop = rs.id_repair_shop |
| 219 | left join project.review r2 on r2.id_repair = r.id_repair |
| 220 | group by rs.id_repair_shop |
| 221 | }}} |
| 222 | |