Final DBMS Assignment 10 Jun 2024
Final DBMS Assignment 10 Jun 2024
DATE - 10/6/2024
Question :
1. Create 'classwork' database. Import classwork-db.sql.
Solution :
Steps to import database file(.sql)
1. Open Workbench
2. Run following queries:
show databases;
create database classwork;
use classwork;
3. Go to databases and click on import tab
4. Select option Individual Database file for import and browse the
classwork-db.sql
5. After selecting database file Click on Start Import button.
6. You will get following screen
Error appeared
ERROR 1046 (3D000) at line 1: No database selected WHILE
database import
To resolve this error edited the given “classwork-db.sql”
Added following sql statement at the starting of file.
USE classwork;
Solution :
Steps to import database file(.sql)
1. Open Workbench
2. Run following queries:
show databases;
create database hr;
use hr;
3. Go to databases and click on import tab
4. Select option Individual Database file for import and browse the
hr-db.sql
5. After selecting database file Click on Start Import button.
6. Error appeared
7. ERROR 1046 (3D000) at line 1: No database selected WHILE
database import
8. To resolve this error edited the given “hr-db.sql”
9. Added following sql statement at the starting of file.
USE hr;
Solution :
1. Open Workbench
2. Run following queries:
show databases;
create database northwind;
use northwind;
3. Go to databases and click on import tab
4. Select option Individual Database file for import and browse the
northwind-db.sql
5. After selecting database file Click on Start Import button.
6. Error appeared
7. ERROR 1046 (3D000) at line 1: No database selected WHILE
database import
8. To resolve this error edited the given “northwind-db.sql”
9. Added following sql statement at the starting of file.
USE northwind;
Solution :
Display all tables from classwork database :
5. Login with your user name (d1_12345). List all tables in sales
database. Display contents of all tables (one by one). Answer the
following questions (by observations only – not queries).
a. How many orders data is present in the database?
b. How many customers are present in the database?
c. How many salespeople are present in the database?
d. On which date order with highest amount is placed?
e. For which order salesman got maximum commission? Hint:
you need to refer data of two tables.
f. Which salesman are handling more than two customers? Hint:
you need to refer data of two tables.
g. Which city have single customer?
h. Which city have multiple salespeople?
Solution :
Display all tables from sales database :
Display contents of customers table:
f. Which salesman are handling more than two customers? Hint: you
need to refer data of two tables.
Ans: There is no salesman in records who handle more than 02
customers.
Solution :
One-to-Many Relationship
7. Write a select command that produces the order number, amount, and
date for all rows in the Orders table.
Solution :
SQL Statement/Query :
Output :
Question :
8. Write a query that displays the Salespeople table with the columns in the
following order: city, sname, snum, comm.
Solution :
SQL Statement/Query :
Output :
Question :
9. Write a query that will produce the snum values of all salespeople from
the Orders table (with the duplicate values suppressed).
Solution :
SQL Statement/Query :
Output :
Question :
10.Write a query that will give you all orders for more than Rs. 1,000.
Solution :
SQL Statement/Query :
Output :
Question :
11.Write a query that will give you the names and cities of all salespeople in
London with a commission above 0.10.
Solution :
SQL Statement/Query :
Output :
Question :
12.Write a query on the Customers table whose output will exclude all customers
with a rating <= 100, unless they are located in Rome.
Solution :
SQL Statement/Query :
Output :
Question :
13.Write a query that selects all orders except those with zeroes or NULLs in the
amt field.
Solution :
SQL Statement/Query :
Output :
14. Write a query to display the first_name, last_name using alias name “First
Name", "Last Name".
Solution :
SQL Statement/Query :
Output :
Question :
15. Write a query to get the names (first_name, last_name), salary, PF of all the
employees (PF is calculated as 15% of salary).
Solution :
SQL Statement/Query :
Output :
Question :
Solution :
SQL Statement/Query :
Output :
Question :
17. Write a query to display job id and job title of first 5 jobs.
Solution :
SQL Statement/Query :
Output :
Note : Question no 18 is missing in assignment
Question :
19. Write a query to display location id, street address and postal code of 6
locations after first 3 locations.
Solution :
SQL Statement/Query :
Output :
Question :
20. Write a query to display job title and difference between max and min salary
for that job.
Solution :
SQL Statement/Query :
Output :
Note: * Use Group by clause with appropriate sql functions to solve
following queries.
Question :
Solution :
SQL Statement/Query :
OR
Output :
Question :
22. Display the country ID and number of cities we have in the country.
Solution :
SQL Statement/Query :
OR
Output :
Question :
23. Display average salary of employees in each department who have commission
percentage.
Solution :
Output :
Question :
24. Display job ID, number of employees, sum of salary, and difference between
highest salary and lowest salary of the employees of the job.
Solution :
SQL Statement/Query :
Output :
Question :
25. Display job ID for jobs with average salary more than 10000.
Solution :
SQL Statement/Query :
Output :
Question :
Solution :
SQL Statement/Query :
Output :
JOIN QUERIES
Question :
Solution :
SQL Statement/Query :
Output :
Question :
Solution :
SQL Statement/Query :
METHOD 01 :
METHOD 02:
Output :
Question :
29. Display job title, department name, employee last name, starting date for all
jobs from 1993 to 1998.
Solution :
SQL Statement/Query :
Output :
Question :
Solution :
SQL Statement/Query :
METHOD 01 :
METHOD 02 :
Output :
Question :
31. Display job title, employee name, and the difference between maximum
salary for the job and salary of the employee.
Solution :
SQL Statement/Query :
METHOD 01 :
METHOD 02 :
Output :