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

Lab 1.1

The document provides examples of SQL queries to retrieve data from various database tables. The queries select, filter, calculate, and display data fields. Functions like IN, BETWEEN, and NVL are used to filter records that meet certain conditions.
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)
566 views

Lab 1.1

The document provides examples of SQL queries to retrieve data from various database tables. The queries select, filter, calculate, and display data fields. Functions like IN, BETWEEN, and NVL are used to filter records that meet certain conditions.
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/ 3

1.

1: Data Query Language


1. Retrieve the details (Name, Salary and dept code) of the employees who are
working in department 20, 30 and 40.

select staff_name,staff_sal,dept_code
from staff_masters
where dept_code in (20,40,30)

2. List the details of the employees with user defined Column headers.

select staff_code as id,staff_name as ename,design_code as job_Code,dept_code as


deptno,staff_dob as DOB, hiredate as Join_date,mgr_code as mgr, staff_sal as
salary, staff_address as address
from staff_masters;

3. Display the code, subjects and total marks for every student. Total Marks will
be calculated as Subject1+Subject2+Subject3. (Refer Student_Marks table)

select student_code,subject1,subject2,subject3,subject1+subject2+subject3 as "Total


Marks"
from student_marks;

4. List the details of the staff whose designations are either PROFESSOR or
LECTURER.
select s.staff_name,s.design_code,d.design_name
from staff_masters s join designation_masters d
on s.design_code=d.design_code
and d.design_name in ('Professor','Lecturer');

5. List the code, name, and department number of the employees who have experience
of more than 18 years.

select staff_code,staff_name,dept_code
where trunc((sysdate-hiredate)/365)>18

6. List the name and Designations of the staff who have joined before Jan 2003.

select staff_name,design_code
from staff_masters
where hiredate<'01-Jan-2003';

7. List the name, designation, and income for 10 years of the employees who are
working in departments 10 and 30.

select staff_name,design_code,staff_sal*120 as income


from staff_masters
where dept_code in (10,30);

8. List the name and experience (in years) of employees who are working as
LECTURER.

select staff_name,design_code,sysdate-hiredate as experience


from staff_masters
where design_code IN(select design_code
from designation_masters
where design_name like '%Lecturer%')
9. Display name concatenated with dept code separated by comma and space. Name the
column as ‘Student Info’.

select staff_name||' , '||dept_code as "Student Info"


from staff_masters;

10. List the Name and Salary of the staff who are earning between 12000 and 25000.
Sort them based on their salaries and name.

select staff_name,staff_sal
from staff_masters
where staff_sal between 12000 and 25000;

11. Display employees who do not have manager.

select * from employees


where manager_id is null

12. Write a query which will display name, department code and date of birth of all
students who were born between January 1, 1981 and March 31, 1983. Sort it based on
date of birth (ascending).

select student_name,dept_code,student_dob
from student_masters
where student_dob between '01-Jan-81' and '31-Mar-83';

13. Get the Department number, and sum of Salary of all non managers where the sum
is greater than 20000.

select dept_code,sum(staff_sal)
from staff_masters
where staff_code not in (select mgr_code from
from staff_masters
where mgr_code not null)
group by dept_code
having sum(staff_sal)>20000

14. Display the details of books that have not been returned and expected return
date was last Monday.

select book_code,to_char(book_expected_return_date,'DD-MON-RR, DAY')


from book_transactions
where book_actual_return_date is null and
book_expected_return_date=next_day(book_expected_return_date-7,'MONDAY');

15. Display the name and department code of students. If student does not belong to
any department, display “No Department”. Label the column as “Department”. (Hint:
Use NVL function)

select student_name,nvl(to_char(dept_code),'No Department') as Department


from student_masters

16. Display the name and salary of the staff. Salary should be represented as X.
Each X represents a 1000 in salary.
Sample Output
JOHN 10000 XXXXXXXXXX
ALLEN 12000 XXXXXXXXXXXX

select staff_name,staff_sal,lpad('X',staff_sal/1000,'X') as salary


from staff_masters

You might also like