-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc0cbca
commit 161a2ba
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- Section1 | ||
SELECT id AS order_id | ||
FROM orders | ||
WHERE status = 'warehouse' | ||
ORDER BY id DESC; | ||
|
||
-- Section2 | ||
SELECT id AS customer_id, name AS customer_name | ||
FROM customers | ||
WHERE id NOT IN (SELECT DISTINCT customer_id FROM orders) | ||
ORDER BY name ASC; | ||
|
||
-- Section3 | ||
SELECT DATE(created_at) AS date, FORMAT(COUNT(*) / (SELECT COUNT(*) FROM orders WHERE status != 'canceled' AND EXISTS(SELECT 1 FROM customers WHERE is_blocked = 0))), 2) * 100, 2) AS cancellation_rate | ||
FROM orders | ||
JOIN customers ON orders.customer_id = customers.id AND is_blocked = 0 AND status = 'canceled' | ||
GROUP BY DATE(created_at); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- Section1 | ||
SELECT * | ||
FROM Customers | ||
WHERE CustomerName LIKE 'A%' | ||
ORDER BY CustomerName ASC; | ||
-- Section2 | ||
DELETE FROM Customers | ||
WHERE Country IN ( | ||
SELECT Country | ||
FROM ( | ||
SELECT Country | ||
FROM Customers | ||
GROUP BY Country | ||
HAVING COUNT(DISTINCT CustomerID) < 5 | ||
) AS subquery | ||
); | ||
-- Section3 | ||
SELECT DISTINCT CustomerName | ||
FROM Customers | ||
WHERE CustomerID IN ( | ||
SELECT CustomerID | ||
FROM Orders | ||
WHERE OrderID IN ( | ||
SELECT OrderID | ||
FROM OrderDetails | ||
WHERE ProductID IN ( | ||
SELECT ProductID | ||
FROM Products | ||
ORDER BY Price ASC | ||
LIMIT 5 | ||
) | ||
) | ||
) | ||
ORDER BY CustomerName ASC; | ||
-- Section4 | ||
SELECT DISTINCT Quantity AS Sales | ||
FROM OrderDetails | ||
WHERE OrderID IN ( | ||
SELECT OrderID | ||
FROM Orders | ||
WHERE MONTH(OrderDate)= MONTH(CURRENT_DATE) | ||
AND YEAR(OrderDate) = YEAR(CURRENT_DATE) | ||
) | ||
ORDER BY Sales DESC | ||
LIMIT 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- Section1 | ||
SELECT * FROM Customers WHERE CustomerName LIKE 'A%' ORDER BY CustomerName ASC; | ||
|
||
-- Section2 | ||
DELETE FROM Customers | ||
WHERE Country IN ( | ||
SELECT Country | ||
FROM Customers | ||
GROUP BY Country | ||
HAVING COUNT(DISTINCT CustomerID) < 5 | ||
); | ||
|
||
-- Section3 | ||
SELECT DISTINCT CustomerName | ||
FROM Customers c JOIN Orders o ON c.CustomerID = o.CustomerID | ||
WHERE EXISTS ( | ||
SELECT * | ||
FROM OrderDetails od JOIN Products p ON od.ProductID = p.ProductID | ||
WHERE od.OrderID = o.OrderID AND p.Price <= ALL( | ||
SELECT Price FROM Products ORDER BY Price LIMIT 5) | ||
) | ||
ORDER BY CustomerName ASC; | ||
|
||
-- Section4 | ||
SELECT ProductID, SUM(Quantity) AS Sales | ||
FROM OrderDetails od JOIN Orders o ON od.OrderID = o.OrderId | ||
WHERE OrderDate BETWEEN DATE_FORMAT(NOW() ,'%Y-%m-01') AND LAST_DAY(NOW()) | ||
GROUP BY ProductId | ||
ORDER BY Sales DESC | ||
LIMIT 10; |