-- 1️⃣ Product টেবিল তৈরি
CREATE TABLE Product (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(100) NOT NULL,
Category VARCHAR(50),
Price DECIMAL(10,2) NOT NULL,
Stock INT NOT NULL
);
-- 2️⃣ Sell টেবিল তৈরি
CREATE TABLE Sell (
SellID INT PRIMARY KEY,
ProductID INT,
Quantity INT NOT NULL,
SellDate DATE NOT NULL,
FOREIGN KEY (ProductID) REFERENCES Product(ProductID)
);
-- 3️⃣ Product ডাটা ইনসার্ট
INSERT INTO Product (ProductID, ProductName, Category, Price, Stock)
VALUES
(1, 'Smart T-Shirt', 'Clothing', 450.00, 50),
(2, 'Smart Jeans', 'Clothing', 1200.00, 30),
(3, 'Sneakers', 'Footwear', 2500.00, 20),
(4, 'Cap', 'Accessories', 300.00, 100);
-- 4️⃣ Sell ডাটা ইনসার্ট
INSERT INTO Sell (SellID, ProductID, Quantity, SellDate)
VALUES
(101, 1, 20, '2025-08-01'),
(102, 1, 15, '2025-08-03'),
(103, 2, 5, '2025-08-04'),
(104, 3, 10, '2025-08-05'),
(105, 4, 12, '2025-08-06'),
(106, 4, 25, '2025-08-07');
-------------------------------------------------
-- প্রশ্ন 2: Retrieve sales details for products with 'Smart' in their name
-------------------------------------------------
SELECT
s.SellID,
p.ProductName,
s.Quantity,
s.SellDate,
(s.Quantity * p.Price) AS TotalPrice
FROM Sell s
JOIN Product p ON s.ProductID = p.ProductID
WHERE p.ProductName LIKE '%Smart%';
-------------------------------------------------
-- প্রশ্ন 3: Retrieve product name and total sales revenue for each product
-------------------------------------------------
SELECT
p.ProductName,
SUM(s.Quantity * p.Price) AS TotalRevenue
FROM Product p
JOIN Sell s ON p.ProductID = s.ProductID
GROUP BY p.ProductName;
-------------------------------------------------
-- প্রশ্ন 4: Categorize sales as High, Medium, or Low
-------------------------------------------------
SELECT
s.SellID,
p.ProductName,
(s.Quantity * p.Price) AS TotalPrice,
CASE
WHEN (s.Quantity * p.Price) > 200 THEN 'High'
WHEN (s.Quantity * p.Price) BETWEEN 100 AND 200 THEN 'Medium'
ELSE 'Low'
END AS SaleCategory
FROM Sell s
JOIN Product p ON s.ProductID = p.ProductID;
-------------------------------------------------
-- প্রশ্ন 5: Calculate the number of days between current date and sale date
-------------------------------------------------
SELECT
s.SellID,
p.ProductName,
s.SellDate,
DATEDIFF(CURRENT_DATE, s.SellDate) AS DaysSinceSale
FROM Sell s
JOIN Product p ON s.ProductID = p.ProductID;