_database queries (3)
_database queries (3)
Exercise #15
Select the name of the products sold by all employees.
2
Exercise #16
Select the name of customers who bought all products purchased by the customer whose identifier is ‘LAZYK’.
3
Exercise #17
Select the name of customers who bought exactly the same products as the customer whose identifier is ‘LAZYK’.
Exercise #18
Select the average price of products by category.
4
Exercise #19
Given the name of the categories and the average price of products in each category.
Exercise #20
Select the identifier and the name of the companies that provide more than 3 products.
Exercise #21
Select the identifier, name, and number of orders of employees, ordered by the employee identifier.
5
Exercise #22
For each employee give the identifier, name, and the number of distinct products sold, ordered by the employee
identifier.
Exercise #23
Select the identifier, name, and total sales of employees, ordered by the employee identifier.
6
Exercise #24
Select the identifier, name, and total sales of employees, ordered by the employee identifier for employees who have
sold more than 70 different products.
Exercise #25
Select the names of employees who sell the products of more than 7 suppliers.
7
Exercise #26
Select the customer name and the product name such that the quantity of this product bought by the customer in a
single order is more than 5 times the average quantity of this product bought in a single order among all clients.
8
SELECT ContactName
FROM Customers
WHERE ContactTitle LIKE '%Manager%'
ORDER BY ContactName;
SELECT *
9
FROM Orders
WHERE OrderDate = '1997-05-19';
Q2: Employees and Customers count from each city that has employees
SELECT e.City,
COUNT(DISTINCT e.EmployeeID) AS EmployeeCount,
COUNT(DISTINCT c.CustomerID) AS CustomerCount
FROM Employees e
LEFT JOIN Customers c ON e.City = c.City
GROUP BY e.City;
FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerID
HAVING COUNT(o.OrderID) > 10;
INSERT INTO Employees (LastName, FirstName, Title, TitleOfCourtesy, BirthDate, HireDate, City, Region,
PostalCode, Country, HomePhone, ReportsTo)
VALUES ('Sharma', 'Aarushi', 'Software Developer', 'Ms.', '2000-01-01', '2025-05-04', 'Bhopal', 'MP', '462042', 'India',
'9876543210', 1);
UPDATE Employees
SET HomePhone = '9998887770'
WHERE FirstName = 'Aarushi' AND LastName = 'Sharma';