Computer Science Problem Sets and Solutions

Problem Sets + Solutions for computer science topics

View the Project on GitHub

SQL 🠊 Online Practice Website 🠊 Northwind Problem Set (MEDIUM)

Q1. Show the ProductName, CompanyName, CategoryName from the products, suppliers, and categories table.

SQL Answer for Q1
SELECT product_name, company_name, category_name
FROM products
JOIN categories ON categories.category_id = products.category_id
JOIN suppliers ON suppliers.supplier_id = products.supplier_id;

Q2. Show the category_name and the average product unit price for each category rounded to 2 decimal places.

SQL Answer for Q2
SELECT category_name, ROUND(AVG(unit_price), 2)
FROM products
JOIN categories ON categories.category_id = products.category_id
GROUP BY category_name;

Q3. Show the city, company_name, contact_name from the customers and suppliers table merged together. Create a column which contains 'customers' or 'suppliers' depending on the table it came from.

SQL Answer for Q3
SELECT city, company_name, contact_name, 'customers' AS role
FROM customers
UNION ALL
SELECT city, company_name, contact_name, 'suppliers' AS role
FROM suppliers;