source: database/Advanced Reports for database/Each store's number of request, including how many have been solved, and how many are still in progress.txt@ 62b2964

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

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 918 bytes
RevLine 
[62b2964]1CREATE OR REPLACE FUNCTION get_store_request_statistics()
2RETURNS TABLE (
3 store_id INT,
4 store_name TEXT,
5 total_requests BIGINT,
6 solved_requests BIGINT,
7 requests_in_progress BIGINT
8)
9LANGUAGE plpgsql
10AS $$
11BEGIN
12 RETURN QUERY
13 SELECT
14 s.store_id,
15 s.name AS store_name,
16 COUNT(r.request_num) AS total_requests,
17 COUNT(
18 CASE
19 WHEN r.customer_satisfaction IS NOT NULL
20 THEN 1
21 END
22 ) AS solved_requests,
23 COUNT(
24 CASE
25 WHEN r.customer_satisfaction IS NULL
26 THEN 1
27 END
28 ) AS requests_in_progress
29 FROM store s
30 LEFT JOIN for_store fs
31 ON s.store_id = fs.store_id
32 LEFT JOIN request r
33 ON fs.request_num = r.request_num
34 GROUP BY
35 s.store_id,
36 s.name
37 ORDER BY
38 total_requests DESC;
39END;
40$$;
Note: See TracBrowser for help on using the repository browser.