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 (EASY)

Q1. Show the category_name and description from the categories table sorted by category_name.

SQL Answer for Q1
SELECT category_name, description
FROM categories
ORDER BY category_name;

Q2. Show all the contact_name, address, city of all customers which are not from 'Germany', 'Mexico', 'Spain'.

SQL Answer for Q2
SELECT contact_name, address, city
FROM customers
WHERE country NOT IN ('Germany', 'Mexico', 'Spain');

Q3. Show order_date, shipped_date, customer_id, Freight of all orders placed on 2018 Feb 26.

SQL Answer for Q3
SELECT order_date, shipped_date, customer_id, freight
FROM orders
WHERE order_date = '2018-02-26';

Q4. Show the employee_id, order_id, customer_id, required_date, shipped_date from all orders shipped later than the required date.

SQL Answer for Q4
SELECT employee_id, order_id, customer_id, required_date, shipped_date
FROM orders
WHERE shipped_date > required_date;

Q5. Show all the even numbered Order_id from the orders table.

SQL Answer for Q5
SELECT order_id
FROM orders
WHERE order_id % 2 = 0;

Q6. Show the city, company_name, contact_name of all customers from cities which contains the letter 'L' in the city name, sorted by contact_name.

SQL Answer for Q6
SELECT city, company_name, contact_name
FROM customers
WHERE city LIKE '%L%'
ORDER BY contact_name;

Q7. Show the company_name, contact_name, fax number of all customers that has a fax number. (not null).

SQL Answer for Q7
SELECT company_name, contact_name, fax 
FROM customers
WHERE fax IS NOT NULL;

Q8. Show the first_name, last_name, hire_date of the most recently hired employee.

SQL Answer for Q8
SELECT first_name, last_name, hire_date
FROM employees
WHERE hire_date = (SELECT MAX(hire_date) FROM employees);

Q9. Show the average unit price rounded to 2 decimal places, the total units in stock, total discontinued products from the products table.

SQL Answer for Q9
SELECT ROUND(AVG(unit_price), 2), SUM(units_in_stock), SUM(discontinued)
FROM products;