source: database/Advanced Reports for database/Employees ordered by total hours worked and total pay.txt@ 06ebe74

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

Project Handcraft Marketplace

  • Property mode set to 100644
File size: 616 bytes
Line 
1CREATE OR REPLACE FUNCTION get_employees_by_hours_and_pay()
2RETURNS TABLE (
3 id BIGINT,
4 employee_name TEXT,
5 total_hours_worked NUMERIC,
6 total_pay NUMERIC
7)
8LANGUAGE plpgsql
9AS $$
10BEGIN
11 RETURN QUERY
12 SELECT
13 e.id,
14 p.name AS employee_name,
15 COALESCE(SUM(w.working_hours), 0) AS total_hours_worked,
16 COALESCE(SUM(w.wage), 0) AS total_pay
17 FROM employees e
18 JOIN personal p
19 ON e.id = p.id
20 LEFT JOIN worked w
21 ON e.id = w.id
22 GROUP BY
23 e.id,
24 p.name
25 ORDER BY
26 total_hours_worked DESC,
27 total_pay DESC;
28END;
29$$;
Note: See TracBrowser for help on using the repository browser.