Index: database/Advanced Reports for database/Top 10 employees who have answered the most amount of request in the last month.txt
===================================================================
--- database/Advanced Reports for database/Top 10 employees who have answered the most amount of request in the last month.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
+++ database/Advanced Reports for database/Top 10 employees who have answered the most amount of request in the last month.txt	(revision 62b296460f935ff5cc47a75f6567f97df5a244a7)
@@ -0,0 +1,31 @@
+CREATE OR REPLACE FUNCTION get_top_10_employees_by_requests_last_month()
+RETURNS TABLE (
+    id BIGINT,
+    employee_name TEXT,
+    number_of_requests BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+    RETURN QUERY
+    SELECT
+        e.id,
+        p.name AS employee_name,
+        COUNT(DISTINCT a.request_num) AS number_of_requests
+    FROM employees e
+    JOIN personal p
+        ON e.id = p.id
+    JOIN answers a
+        ON e.id = a.id
+    JOIN request r
+        ON a.request_num = r.request_num
+    WHERE r.date_and_time >= date_trunc('month', CURRENT_DATE) - INTERVAL '1 month'
+      AND r.date_and_time < date_trunc('month', CURRENT_DATE)
+    GROUP BY
+        e.id,
+        p.name
+    ORDER BY
+        number_of_requests DESC
+    LIMIT 10;
+END;
+$$;
