main
|
Last change
on this file since 6c7cfa6 was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago |
|
Project Handcraft Marketplace
|
-
Property mode
set to
100644
|
|
File size:
616 bytes
|
| Line | |
|---|
| 1 | CREATE OR REPLACE FUNCTION get_employees_by_hours_and_pay()
|
|---|
| 2 | RETURNS TABLE (
|
|---|
| 3 | id BIGINT,
|
|---|
| 4 | employee_name TEXT,
|
|---|
| 5 | total_hours_worked NUMERIC,
|
|---|
| 6 | total_pay NUMERIC
|
|---|
| 7 | )
|
|---|
| 8 | LANGUAGE plpgsql
|
|---|
| 9 | AS $$
|
|---|
| 10 | BEGIN
|
|---|
| 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;
|
|---|
| 28 | END;
|
|---|
| 29 | $$; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.