Practical Techniques for Returning Result Sets in PostgreSQL
This resource offers a total of 50 PostgreSQL Returning result sets from functions problems for practice. It includes 10 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
1. Return All Employees
Write a PostgreSQL query to create a function that returns all rows from the Employees table as a result set.
2. Filter Employees by Department
Write a PostgreSQL query to create a function that returns a result set of employees filtered by a given department ID.
3. Aggregated Sales Data by Region
Write a PostgreSQL query to create a function that returns aggregated sales data grouped by region from the Sales table.
4. Return Orders Above a Threshold
Write a PostgreSQL query to create a function that returns a result set of orders where the total exceeds a specified threshold.
5. Customer Details with RETURNS TABLE
Write a PostgreSQL query to create a function using the RETURNS TABLE clause to return customer details (ID, name, email) from the Customers table.
6. Products under a Specified Price
Write a PostgreSQL query to create a function that returns a result set of products with a price lower than a given value.
7. Sorted Customer List
Write a PostgreSQL query to create a function that returns a result set of customers with an optional sorting order based on an input parameter (ASC/DESC) for the customer name.
8. Employee and Department Join
Write a PostgreSQL query to create a function that returns a result set by joining the Employees and Departments tables on the department_id.
9. Return Orders Cursor
Write a PostgreSQL query to create a function that opens a cursor and returns a result set of orders placed in the last month.
10. Filtered Sales by Date Range
Write a PostgreSQL query to create a function that returns a result set of sales records within a specified date range.
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics