source: database/Advanced Database Developement/Views/Store performance overview.txt@ 33517cc

finki-main main
Last change on this file since 33517cc was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 686 bytes
Line 
1CREATE OR REPLACE VIEW vw_store_performance AS
2SELECT
3 s.store_id,
4 s.name AS store_name,
5 s.date_of_founding,
6 s.rating,
7
8 COUNT(DISTINCT r.date) AS number_of_reports,
9 COALESCE(SUM(r.profit), 0) AS total_reported_profit,
10 COALESCE(MAX(r.overall_profit), 0) AS overall_profit,
11
12 COALESCE(SUM(ed.sales), 0) AS total_sales,
13 COALESCE(SUM(ed.damages), 0) AS total_damages,
14 COALESCE(SUM(ed.monthly_profit), 0) AS total_monthly_profit
15
16FROM store s
17LEFT JOIN report r
18 ON r.store_id = s.store_id
19LEFT JOIN exchanges_data ed
20 ON ed.store_id = r.store_id
21 AND ed.date = r.date
22
23GROUP BY
24 s.store_id,
25 s.name,
26 s.date_of_founding,
27 s.rating;
Note: See TracBrowser for help on using the repository browser.