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

SQL Sales Table Creation and Queries

The document contains SQL code for creating a Sales table, inserting sample data, and executing various queries to retrieve records and calculate total sales amounts. It includes outputs for retrieving all records, total sales per customer, and specific orders for laptops in January 2025. The SQL queries utilize standard SQL functions and SQLite date functions for filtering data.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

SQL Sales Table Creation and Queries

The document contains SQL code for creating a Sales table, inserting sample data, and executing various queries to retrieve records and calculate total sales amounts. It includes outputs for retrieving all records, total sales per customer, and specific orders for laptops in January 2025. The SQL queries utilize standard SQL functions and SQLite date functions for filtering data.

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 PDF, TXT or read online on Scribd

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

You might also like