0% found this document useful (0 votes)
3 views1 page

SQL

The document outlines SQL commands to create a Sales table, insert sample data, and perform various queries. It includes commands to retrieve all records, calculate total sales amounts per customer, and filter Laptop orders from January 2025. The data is structured with fields for OrderID, CustomerName, Product, Quantity, Price, and OrderDate.

Uploaded by

susmithareddy959
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

SQL

The document outlines SQL commands to create a Sales table, insert sample data, and perform various queries. It includes commands to retrieve all records, calculate total sales amounts per customer, and filter Laptop orders from January 2025. The data is structured with fields for OrderID, CustomerName, Product, Quantity, Price, and OrderDate.

Uploaded by

susmithareddy959
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

-- 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;

You might also like