Queries For Sample Customers Database
Queries For Sample Customers Database
4. Find unique product codes for products that have been ordered:
Groupby Keyword
5. Find the earliest and latest order date for each customer:
9. Which customers have placed orders, and what are their order numbers?
10. List customers who have made payments, along with the payment dates.
13. Question: What are the names and job titles of employees and their respective
managers?
14. Question: List customers who have placed orders, along with their order numbers and
order dates.
SELECT c.customerName, o.orderNumber, o.orderDate
FROM customers c, orders o
WHERE c.customerNumber = o.customerNumber;
15. Question: Which products have been ordered, and what is the total quantity ordered
for each product?
16. Question: Show the names of customers and their sales representatives (if available).
17. What are the names of products in the 'Classic Cars' product line, and what is their
product scale?
18. What are the names and contact information of customers who have placed orders?
19. Which employees report to a specific manager, and what are their job titles?
Query:
SELECT e.firstName, e.lastName, e.jobTitle
FROM employees e
WHERE e.reportsTo = 1143; -- Replace with the manager's employeeNumber
20. Question: What are the names of products ordered by customers in a specific city?
SELECT p.productName
FROM products p
JOIN orderdetails od ON p.productCode = od.productCode
JOIN orders o ON od.orderNumber = o.orderNumber
JOIN customers c ON o.customerNumber = c.customerNumber
WHERE c.city = 'New York'; -- Replace with the desired city
21. Question: What are the names of customers who have made payments, and what is
the total amount paid by each customer?
SELECT p.productName
FROM products p
LEFT JOIN orderdetails od ON p.productCode = od.productCode
WHERE od.productCode IS NULL;
23. Question: Which employees report to each manager, and what are their names?
24. Question: What are the names of customers who have made payments, and what is
the total amount each customer has paid?
25. Question: Which products were ordered by customers and how many of each product
were ordered?
27. Question: What are the names of products in the 'Vintage Cars' product line, and what
is their stock quantity?