Adarsh SQL2
Adarsh SQL2
Adarsh Choudhary
M2022BSASS003
1. USE AssessmentDB;
The Workers table contains the following fields: Worker_ID, First_Name, Last_Name, Salary,
Joining_Date, and Department.
1. INSERT INTO Workers (Worker_ID, First_Name, Last_Name, Salary, Joining_Date, Department) VALUES
2. (1, 'Monika', 'Arora', 100000, '2014-02-20', 'HR'),
3. (2, 'Niharika', 'Verma', 80000, '2016-06-11', 'Admin'),
4. (3, 'Jenisha', 'Patel', 350000, '2018-02-20', 'Programmer'),
5. (4, 'Amitabh', 'Singh', 50000, '2014-02-20', 'Admin'),
6. (5, 'Vivek', 'Bhatia', 500000, '2018-06-11', 'Admin'),
7. (6, 'Vipul', 'Diwan', 200000, '2014-06-11', 'Account'),
8. (7, 'Satish', 'Kumar', 75000, '2020-01-20', 'Account'),
9. (8, 'Geetika', 'Chauhan', 90000, '2017-04-10', 'Admin');
Output:
1. SELECT *
2. FROM Workers
3. ORDER BY Salary DESC;
Output:
Question 2: Retrieve the First Two Characters of Each Worker’s First Name
This query extracts the first two characters of each worker’s first name:
1. SELECT SUBSTRING(First_Name, 1, 2) AS First_Two_Chars
2. FROM Workers;
Output:
Question 3: Count Workers Who Joined Between April 10, 2017, and June 20,
2018
This query counts workers whose joining dates fall within the specified range:
Output:
This query retrieves the second-to-last record from the Workers table:
1. SELECT *
2. FROM Workers
3. ORDER BY Worker_ID DESC
4. LIMIT 1 OFFSET 1;
Output:
This query excludes workers with the first names "Vipul" and "Jenisha":
1. SELECT *
2. FROM Workers
3. WHERE First_Name NOT IN ('Vipul', 'Jenisha');
Output:
This query groups workers by department and arranges them in ascending order of salary:
Output:
1. SELECT *
2. FROM Workers
3. WHERE MOD(Worker_ID, 2) <> 0;
Output:
Question 8: Display Bottom 15% of Records by Salary
This query displays the bottom 15% of records when sorted by salary:
Output:
Question 9: Fetch Each Department Along with the Total Salaries Paid
This query calculates the total salaries paid for each department:
1. SELECT Department,
2. SUM(Salary) AS Total_Salaries
3. FROM Workers
4. GROUP BY Department;
Output:
Question 10: Find Customers Who Have Not Placed Any Orders
This query retrieves customers who have not placed any orders. First, create the Customers and
Orders tables:
1. SELECT Customer_ID,
2. Customer_Name
3. FROM Customers
4. WHERE Customer_ID NOT IN (
5. SELECT DISTINCT Customer_ID
6. FROM Orders
7. );
Output: