Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-robot77 committed Aug 12, 2023
1 parent cc0cbca commit 161a2ba
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Question Bank/Not Done/Estekhraj.sql
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);
45 changes: 45 additions & 0 deletions Question Bank/Not Done/Hesab o Ketab-2.sql
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;
30 changes: 30 additions & 0 deletions Question Bank/Not Done/Hesab o Ketab.sql
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;

0 comments on commit 161a2ba

Please sign in to comment.