Here are some of the exercises for which you can write SQL queries to self evaluate.
Ensure that we have required database and user for retail data. We might provide the database as part of our labs. Here are the instructions to use psql
for setting up the required database (if required) and tables.
Create Tables using the script provided. You can either use psql
or SQL Workbench.
You can drop the existing tables.
Once the tables are dropped you can run below script to create the tables for the purpose of exercises.
Data shall be loaded using the script provided.
Run queries to validate we have data in all the 3 tables.
Get order count per customer for the month of 2014 January.
Tables - orders and customers
Data should be sorted in descending order by count and ascending order by customer id.
Output should contain customer_id, customer_first_name, customer_last_name and customer_order_count.
Get the customer details who have not placed any order for the month of 2014 January.
Tables - orders and customers
Data should be sorted in ascending order by customer_id
Output should contain all the fields from customers
Get the revenue generated by each customer for the month of 2014 January
Tables - orders, order_items and customers
Data should be sorted in descending order by revenue and then ascending order by customer_id
Output should contain customer_id, customer_first_name, customer_last_name, customer_revenue.
If there are no orders placed by customer, then the corresponding revenue for a give customer should be 0.
Consider only COMPLETE and CLOSED orders
Get the revenue generated for each category for the month of 2014 January
Tables - orders, order_items, products and categories
Data should be sorted in ascending order by category_id.
Output should contain all the fields from category along with the revenue as category_revenue.
Consider only COMPLETE and CLOSED orders
Get the products for each department.
Tables - departments, categories, products
Data should be sorted in ascending order by department_id
Output should contain all the fields from department and the product count as product_count