-- 1.
Create a Sales table
CREATE TABLE Sales (
OrderID INTEGER PRIMARY KEY,
CustomerName TEXT,
Product TEXT,
Quantity INTEGER,
Price REAL,
OrderDate TEXT -- Stored in YYYY-MM-DD format
);
-- 2. Insert sample data
INSERT INTO Sales (OrderID, CustomerName, Product, Quantity, Price, OrderDate)
VALUES
(1, 'Chinni', 'Laptop', 1, 55000.00, '2025-01-12'),
(2, 'Ravi', 'Mobile', 2, 15000.00, '2025-01-15'),
(3, 'Sita', 'Tablet', 1, 22000.00, '2025-02-05'),
(4, 'Arjun', 'Laptop', 1, 60000.00, '2025-02-10');
-- 3. Retrieve all records
SELECT * FROM Sales;
-- 4. Calculate total sales amount for each customer
SELECT CustomerName,
SUM(Quantity * Price) AS TotalAmount
FROM Sales
GROUP BY CustomerName;
-- 5. Get all Laptop orders in January 2025 (SQLite date functions)
SELECT *
FROM Sales
WHERE Product = 'Laptop'
AND strftime('%m', OrderDate) = '01'
AND strftime('%Y', OrderDate) = '2025'
ORDER BY OrderDate ASC;