SQL Code and Output
SQL Code:
-- 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;
Query Outputs
1. Retrieve all records from Sales table
OrderID CustomerName Product Quantity Price OrderDate
1 Chinni Laptop 1 55000.0 2025-01-12
2 Ravi Mobile 2 15000.0 2025-01-15
3 Sita Tablet 1 22000.0 2025-02-05
4 Arjun Laptop 1 60000.0 2025-02-10
2. Total sales amount for each customer
CustomerName TotalAmount
Chinni 55000.0
Ravi 30000.0
Sita 22000.0
Arjun 60000.0
3. Laptop orders in January 2025
OrderID CustomerName Product Quantity Price OrderDate
1 Chinni Laptop 1 55000.0 2025-01-12