0% found this document useful (0 votes)
1 views

DBMS code

.

Uploaded by

joshihimanshu358
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)
1 views

DBMS code

.

Uploaded by

joshihimanshu358
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
You are on page 1/ 20

Week 3

1. Create an employee table with the following attributes and constraints:


Employee Table -
• Employee Id. (Primary key)
• Name
• Department
• Age (check >18)
• Salary
• City
Solution Query:

2. Display the total number of employees.


Solution Query:

21
3. Retrieve all information of employees whose age is 22.
Solution Query:

4. Fetch the employee id, name, and department, whose salary >= 50000.
Solution Query:

5. Print the name of the employees and label the column as "Full Name" for those employees
whose department name is 'Finance' and age is 22.
Solution Query:

22
6. Print the department names from the employee table without having the duplicates.
Solution Query:

23
Week 4
1. Find out the maximum and minimum salary from the employee table.
Solution Query:

2. Show the total salary and average salary of all the employees.
Solution Query:

3. Show all the details of the employees who have the same salary.
Solution Query:

24
4. Display the employees name from lowest salary to the highest salary.
Solution Query:

5. Display the employee name and salary (department-wise) for employees, whose salary is
greater than or equal to 10,000 and age is greater than 25.
Solution Query:

25
Week 5
1. Fetch the information of employees who belong to the city "Delhi" or "Pune."
Solution Query:

2. Print the name and department of employees whose ID is in the range from 2001 to 2005.
Solution Query:

3. Show the names of employees who belong to the same city (use the IN operator).
Solution Query:

26
4. Check whether the all employee is belongs to the same city or not. (use ALL operator)
Solution Query:

5. Check whether the all employee is belongs to the same city or not. (use ANY operator)
Solution Query:

6. Check whether the all employee is belongs to the same city or not. (use Exists operator)
Solution Query:

27
Week 6
1. Show the record of employees who are working in the 'CSE' department.
Solution Query:

2. Fetch the names of employees whose names start with the letters 'ay'.
Solution Query:

3. Fetch the information of employees, including their names and departments, whose names
end with the letters 'sh'.
Solution Query:

4. Display the employee names and their departments of employees, whose city name starts
with 'D' or ends with 'h'.
Solution Query:

28
5. Print all records of employees whose salary is greater than 15,000 and whose name starts
with 'h'.
Solution Query:

6. Print the names of employees whose names consist of exactly three letters.
Solution Query:

7. Print the names of employees along with their city for those whose names have at least five
letters.
Solution Query:

29
Week 7
1. Create two tables named as employee and department with the given constraints and
attributes:
Employee table - (Employee Id.(Primary key), Department ID, Name, Age (check >18),
Salary, City)
Department table - (Department Id, and Department name)
Solution Query:

2. Display the details of employees along with their corresponding department names.
Solution Query:

30
3. Print the names of employees who are not assigned to any department.
Solution Query:

4. Print the employee names and department names for employees whose salary is greater
than 25,000. (Using left join).
Solution Query:

5. Display the names of employees along with their department names for those who are not
assigned to any department.
Solution Query:

31
6. Print the employee names and their corresponding department names for employees with a
salary greater than 25,000. (Using right join).
Solution Query:

7. Display the names of departments along with the names of employees who are older than 30
years.

Solution Query:

32
Week 8
1. Create the table to keep track of customer records and their order.
Customer table - (Name as Not null, Customer_id as primary key, Age, Address)
Order table - (Customer_id, order_id, date).
Solution Query:

2. Apply the full join and the full outer join to the schema and review the results.
Solution Query:

3. Display the name of the city as "destination" for customers who have placed orders.
Solution Query:

33
4. Apply the cross join and check the results.
Solution Query:

34
5. Display the customer names and order IDs for customers who have placed orders from the
same city.
Solution Query:

35
Week 9
1. Create the Student table, Register table and Program table.
Student table - ( Roll no. as primary key, Name as not null, city)
Program table - ( Program ID as primary key, Program Name as not null, Program Fee not
less than 10000, Department)
Register table - ( Program ID and Roll no. as primary composite key)
Solution Query:

2. Display the details of students who are registered in the "MCA" program.
Solution Query:

36
3. Display the list of all students, who are registered in at least one program.
Solution Query:

4. Display the details of programs that have fees greater than the average fee.
Solution Query:

5. Display the names of students who are registered in a program having fees less than 30000.
Solution Query:

37
6. Display the details of students who have not registered in any course.
Solution Query:

7. Display the names of programs in which a maximum number of students are registered.
Solution Query:

8. Display the names of programs in which a minimum number of students are registered.
Solution Query:

38
Week 10
1. Find out the second minimum salary of an employee.
Solution Query:

2. Find out the second minimum salary of an employee without using limit, dense range, and
order by clause.
Solution Query:

3. Find out the third maximum salary of an employee.


Solution Query:

4. Find out the third maximum salary of an employee without using limit, dense range, and
order by clause.
Solution Query:

39
5. Display the names and salaries of employees who earn more than the average salary of their
department.
Solution Query:

6. Fetch the list of the employee who belongs to the same department but earns less than the
second employee.
Solution Query:

7. Display the names of employees who are older than their colleagues in the same department.
Solution Query:

40

You might also like