0% found this document useful (0 votes)
2 views2 pages

Assignment On SQL Functions

The document outlines SQL assignments involving the creation of two tables: employee_salaries and orders, along with sample data insertion. It includes a series of queries to manipulate and retrieve data, such as calculating salaries, filtering orders, and analyzing sales. The queries cover various SQL functions and operations to demonstrate data handling and reporting capabilities.

Uploaded by

katikaveni103
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)
2 views2 pages

Assignment On SQL Functions

The document outlines SQL assignments involving the creation of two tables: employee_salaries and orders, along with sample data insertion. It includes a series of queries to manipulate and retrieve data, such as calculating salaries, filtering orders, and analyzing sales. The queries cover various SQL functions and operations to demonstrate data handling and reporting capabilities.

Uploaded by

katikaveni103
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
You are on page 1/ 2

--Assignment on SQL Functions

-- Create the table


CREATE TABLE employee_salaries (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department VARCHAR(50),
position VARCHAR(50),
hire_date DATE,
salary DECIMAL(10, 2)
);

-- Insert sample data into the table


INSERT INTO employee_salaries (employee_id, first_name, last_name, department,
position, hire_date, salary) VALUES
(1, 'John', 'Doe', 'Finance', 'Analyst', '2019-05-12', 55000.00),
(2, 'Jane', 'Smith', 'Marketing', 'Manager', '2018-03-23', 72000.00),
(3, 'Paul', 'Johnson', 'IT', 'Developer', '2021-08-15', 65000.00),
(4, 'Emily', 'Davis', 'HR', 'Recruiter', '2020-11-30', 47000.00),
(5, 'Michael', 'Brown', 'Finance', 'Accountant', '2017-06-05', 60000.00),
(6, 'Sarah', 'Wilson', 'Marketing', 'Assistant', '2022-01-12', 40000.00),
(7, 'David', 'Lee', 'IT', 'System Administrator', '2016-04-20', 78000.00),
(8, 'Linda', 'Taylor', 'Operations', 'Coordinator', '2018-10-17', 52000.00),
(9, 'James', 'Anderson', 'Sales', 'Sales Executive', '2020-02-10', 58000.00),
(10, 'Patricia', 'Thomas', 'Customer Service', 'Support Agent', '2021-07-25',
45000.00);

SELECT * FROM employee_salaries

-- Create the table


CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE,
product_name VARCHAR(100),
quantity INT,
unit_price DECIMAL(10, 2),
total_amount DECIMAL(10, 2),
order_status VARCHAR(20)
);

-- Insert sample data into the table


INSERT INTO orders (order_id, customer_id, order_date, product_name, quantity,
unit_price, total_amount, order_status) VALUES
(1, 101, '2024-01-15', 'Laptop', 1, 1200.00, 1200.00, 'Shipped'),
(2, 102, '2024-02-20', 'Smartphone', 2, 500.00, 1000.00, 'Delivered'),
(3, 103, '2024-03-05', 'Office Chair', 3, 150.00, 450.00, 'Processing'),
(4, 104, '2024-04-10', 'Desk', 1, 300.00, 300.00, 'Cancelled'),
(5, 105, '2024-05-25', 'Tablet', 1, 350.00, 350.00, 'Shipped'),
(6, 106, '2024-06-15', 'Monitor', 2, 200.00, 400.00, 'Delivered'),
(7, 107, '2024-07-10', 'Keyboard', 5, 40.00, 200.00, 'Processing'),
(8, 108, '2024-08-05', 'Mouse', 10, 25.00, 250.00, 'Delivered'),
(9, 109, '2024-09-12', 'Printer', 1, 150.00, 150.00, 'Shipped'),
(10, 110, '2024-10-01', 'Headphones', 3, 80.00, 240.00, 'Delivered');

SELECT * FROM ORDERS


1. Concatenate first and last names as fullname from a table employee_Salaries
table.
2.Calculate average, maximum, and rounded salary from an employee_salaries table.
3.Filter records in orders table between '2024-01-01' and '2024-12-31':
4. Write a query to retrieve all orders that are currently in "Processing" status.
5. Write a query to calculate the total sales (total_amount) for each month in
2024.
6.Write a query to find the average total_amount of all completed orders (status
"Delivered").
7.Write a query to find the highest and lowest total_amount orders from the orders
table.
8.Write a query to find all orders where the total_amount is greater than $500.
9.Write a query to display the count of orders for each order_status.
10.Write a query to list the top 3 most ordered products based on the quantity
ordered.
11. Write a query to find the customer_ids of customers who have placed more than
one order.
12. Write a query to calculate the total revenue generated by each product
(product_name).
13.Write a query to list all orders placed between '2024-03-01' and '2024-06-30'.
14.Write a query to find the first and last order date for each customer.
15.Assuming a 7% sales tax, write a query to calculate the sales tax and total
amount including tax for each order.
16.Write a query to display the number of orders placed each month in 2024.
17.Write a query to extract the month and year from the order_date and format it as
"Month YYYY" (e.g., "January 2024").
18.Write a query to calculate the cumulative sales (total_amount) for all orders
sorted by order_date.
19.Write a query to find all orders that contain the word "Laptop" in the
product_name.
20.Assume orders over $1000 have a 10% discount. Write a query to calculate the
discounted price for such orders.
21.Write a query to group orders by quarter and show the total sales in each
quarter.
22.Write a query to list all orders for a customer with customer_id = 105,
including the order details and total amount.

You might also like