Q1. Top 3 highest-paid employees
Show the name, job title and salary of the 3 highest-paid employees.
SELECT name, job_title, salary
FROM employees
ORDER BY salary DESC
LIMIT 3;
-- name | job_title | salary
-- Arjun | Engineering Head | 150000
-- Omkar | Finance Head | 130000
-- Gauri | Sales Head | 120000Q2. Engineering employees earning above 90000
List employees of department 1 (Engineering) earning more than 90000, highest salary first. Break ties by name.
SELECT name, job_title, salary
FROM employees
WHERE dept_id = 1
AND salary > 90000
ORDER BY salary DESC, name;
-- name | job_title | salary
-- Arjun | Engineering Head | 150000
-- Bhavna | Senior Engineer | 110000
-- Chirag | Engineer | 95000
-- Tara | Engineer | 95000Q3. Customer names ending with 'a'
Find customers whose name ends with the letter 'a'.
SELECT customer_id, name, city
FROM customers
WHERE name LIKE '%a'
ORDER BY customer_id;
-- customer_id | name | city
-- 2 | Bina | Mumbai
-- 4 | Divya | Pune
-- 8 | Heena | Pune
-- 10 | Jaya | Mumbai
-- 12 | Leela | ChennaiQ4. Products in selected categories and price range
List products in the Electronics or Fashion category priced between 2000 and 40000 (inclusive), most expensive first.
SELECT name, category, price
FROM products
WHERE category IN ('Electronics', 'Fashion')
AND price BETWEEN 2000 AND 40000
ORDER BY price DESC;
-- name | category | price
-- Smartphone | Electronics | 30000
-- Headphones | Electronics | 3000
-- Sunglasses | Fashion | 2500Q5. Customers without an email
Find customers who have no email address on record.
SELECT customer_id, name, city
FROM customers
WHERE email IS NULL;
-- customer_id | name | city
-- 10 | Jaya | MumbaiQ6. Distinct customer cities
List each city where we have customers, once, in alphabetical order.
SELECT DISTINCT city
FROM customers
ORDER BY city;
-- Bangalore, Chennai, Delhi, Mumbai, PuneQ7. Delivered orders in March 2024
List all delivered orders placed in March 2024.
SELECT order_id, customer_id, order_date
FROM orders
WHERE status = 'Delivered'
AND order_date >= '2024-03-01'
AND order_date < '2024-04-01'
ORDER BY order_date;
-- order_id | customer_id | order_date
-- 8 | 6 | 2024-03-02
-- 9 | 7 | 2024-03-09
-- 11 | 3 | 2024-03-22