SlideShare a Scribd company logo
ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT
Compiled By:- Melaku Tewoldebrehan(BSc.) Page 1
Worksheet Prepared For Database Administration Trainees
SQL Queries And Answeres
Create the following Tables:
LOCATION
Location_ID Regional_Group
122 NEW YORK
123 DALLAS
124 CHICAGO
167 BOSTON
DEPARTMENT
Department_ID Name Location_ID
10 ACCOUNTING 122
20 RESEARCH 124
30 SALES 123
40 OPERATIONS 167
JOB
Job_ID Function
667 CLERK
668 STAFF
669 ANALYST
670 SALESPERSON
671 MANAGER
672 PRESIDENT
EMPLOYEE
EMPL
OYEE
_ID
LAST_N
AME
FIRST
_NAM
E
MID
DLE
_NA
ME
JOB_I
D
MANA
GER_I
D
HIREDATE
SALAR
Y
COMM
DEPA
RTME
NT_ID
7369 SMITH JOHN Q 667 7902 17-DEC-84 800 NULL 20
7499 ALLEN KEVIN J 670 7698 20-FEB-85 1600 300 30
7505 DOYLE JEAN K 671 7839 04-APR-85 2850 NULL 30
7506 DENNIS LYNN S 671 7839 15-MAY-85 2750 NULL 30
7507 BAKER
LESLI
E
D 671 7839 10-JUN-85 2200 NULL 40
7521 WARK
CYNT
HIA
D 670 7698 22-FEB-85 1250 500 30
Queries based on the above tables:
ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT
Compiled By:- Melaku Tewoldebrehan(BSc.) Page 2
Simple Queries:
1. List all the employee details
2. List all the department details
3. List all job details
4. List all the locations
5. List out first name,last name,salary, commission for all employees
6. List out employee_id,last name,department id for all employees and rename employee id
as “ID of the employee”, last name as “Name of the employee”, department id as
“department ID”
7. List out the employees anuual salary with their names only.
Where Conditions:
8. List the details about “SMITH”
9. List out the employees who are working in department 20
10. List out the employees who are earning salary between 3000 and 4500
11. List out the employees who are working in department 10 or 20
12. Find out the employees who are not working in department 10 or 30
13. List out the employees whose name starts with “S”
14. List out the employees whose name start with “S” and end with “H”
15. List out the employees whose name length is 4 and start with “S”
16. List out the employees who are working in department 10 and draw the salaries more than
3500
17. list out the employees who are not receiving commission.
Order By Clause:
18. List out the employee id, last name in ascending order based on the employee id.
19. List out the employee id, name in descending order based on salary column
20. list out the employee details according to their last_name in ascending order and salaries in
descending order
21. list out the employee details according to their last_name in ascending order and then on
department_id in descending order.
Group By & Having Clause:
22. How many employees who are working in different departments wise in the organization
23. List out the department wise maximum salary, minimum salary, average salary of the
employees
24. List out the job wise maximum salary, minimum salary, average salaries of the employees.
25. List out the no.of employees joined in every month in ascending order.
26. List out the no.of employees for each month and year, in the ascending order based on the
year, month.
27. List out the department id having atleast four employees.
28. How many employees in January month.
29. How many employees who are joined in January or September month.
30. How many employees who are joined in 1985.
31. How many employees joined each month in 1985.
32. How many employees who are joined in March 1985.
33. Which is the department id, having greater than or equal to 3 employees joined in April
1985.
Sub-Queries
ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT
Compiled By:- Melaku Tewoldebrehan(BSc.) Page 3
34. Display the employee who got the maximum salary.
35. Display the employees who are working in Sales department
36. Display the employees who are working as “Clerk”.
37. Display the employees who are working in “New York”
38. Find out no.of employees working in “Sales” department.
39. Update the employees salaries, who are working as Clerk on the basis of 10%.
40. Delete the employees who are working in accounting department.
41. Display the second highest salary drawing employee details.
42. Display the Nth highest salary drawing employee details
Sub-Query operators: (ALL,ANY,SOME,EXISTS)
43. List out the employees who earn more than every employee in department 30.
44. List out the employees who earn more than the lowest salary in department 30.
45. Find out whose department has not employees.
46. Find out which department does not have any employees.
Co-Related Sub Queries:
47.Find out the employees who earn greater than the average salary for their department.
Joins
Simple join
48.List our employees with their department names
49.Display employees with their designations (jobs)
50.Display the employees with their department name and regional groups.
51.How many employees who are working in different departments and display with
department name.
52.How many employees who are working in sales department.
53.Which is the department having greater than or equal to 5 employees and display the
department names in ascending order.
54.How many jobs in the organization with designations.
55.How many employees working in “New York”.
Non – Equi Join:
56.Display employee details with salary grades.
57.List out the no. of employees on grade wise.
58.Display the employ salary grades and no. of employees between 2000 to 5000 range of
salary.
Self Join:
59.Display the employee details with their manager names.
60.Display the employee details who earn more than their managers salaries.
61.Show the no. of employees working under every manager.
Outer Join:
61.Display employee details with all departments.
62.Display all employees in sales or operation departments.
Set Operators:
63.List out the distinct jobs in Sales and Accounting Departments.
64.List out the ALL jobs in Sales and Accounting Departments.
65.List out the common jobs in Research and Accounting Departments in ascending order.
ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT
Compiled By:- Melaku Tewoldebrehan(BSc.) Page 4
Answers
1. SQL > Select * from employee;
2. SQL > Select * from department;
3. SQL > Select * from job;
4. SQL > Select * from loc;
5. SQL > Select first_name, last_name, salary, commission from employee;
6. SQL > Select employee_id “id of the employee”, last_name “name", department id as
“department id” from employee;
7. SQL > Select last_name, salary*12 “annual salary” from employee
8. SQL > Select * from employee where last_name=’SMITH’;
9. SQL > Select * from employee where department_id=20
10. SQL > Select * from employee where salary between 3000 and 4500
11. SQL > Select * from employee where department_id in (20,30)
12. SQL > Select last_name, salary, commission, department_id from employee where
department_id not in (10,30)
13. SQL > Select * from employee where last_name like ‘S%’
14. SQL > Select * from employee where last_name like ‘S%H’
15. SQL > Select * from employee where last_name like ‘S___’
16. SQL > Select * from employee where department_id=10 and salary>3500
17. SQL > Select * from employee where commission is Null
18. SQL > Select employee_id, last_name from employee order by employee_id
19. SQL > Select employee_id, last_name, salary from employee order by salary desc
20. SQL > Select employee_id, last_name, salary from employee order by last_name, salary
desc
21. SQL > Select employee_id, last_name, salary from employee order by last_name,
department_id desc
22. SQL > Select department_id, count(*), from employee group by department_id
23. SQL > Select department_id, count(*), max(salary), min(salary), avg(salary) from
employee group by department_id
24. SQL > Select job_id, count(*), max(salary), min(salary), avg(salary) from employee group
by job_id
25. SQL > Select to_char(hire_date,’month’)month, count(*) from employee group by
to_char(hire_date,’month’) order by month
26. SQL > Select to_char(hire_date,’yyyy’) Year, to_char(hire_date,’mon’) Month, count(*) “No.
of employees” from employee group by to_char(hire_date,’yyyy’), to_char(hire_date,’mon’)
27. SQL > Select department_id, count(*) from employee group by department_id having
count(*)>=4
28. SQL > Select to_char(hire_date,’mon’) month, count(*) from employee group by
to_char(hire_date,’mon’) having to_char(hire_date,’mon’)=’jan’
ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT
Compiled By:- Melaku Tewoldebrehan(BSc.) Page 5
29. SQL > Select to_char(hire_date,’mon’) month, count(*) from employee group by
to_char(hire_date,’mon’) having to_char(hire_date,’mon’) in (‘jan’,’sep’)
30. SQL > Select to_char(hire_date,’yyyy’) Year, count(*) from employee group by
to_char(hire_date,’yyyy’) having to_char(hire_date,’yyyy’)=1985
31. SQL > Select to_char(hire_date,’yyyy’)Year, to_char(hire_date,’mon’) Month, count(*) “No.
of employees” from employee where to_char(hire_date,’yyyy’)=1985 group by
to_char(hire_date,’yyyy’),to_char(hire_date,’mon’)
32. SQL > Select to_char(hire_date,’yyyy’)Year, to_char(hire_date,’mon’) Month, count(*) “No.
of employees” from employee where to_char(hire_date,’yyyy’)=1985 and
to_char(hire_date,’mon’)=’mar’ group by
to_char(hire_date,’yyyy’),to_char(hire_date,’mon’)
33. SQL > Select department_id, count(*) “No. of employees” from employee where
to_char(hire_date,’yyyy’)=1985 and to_char(hire_date,’mon’)=’apr’ group by
to_char(hire_date,’yyyy’), to_char(hire_date,’mon’), department_id having count(*)>=3
34. SQL > Select * from employee where salary=(select max(salary) from employee)
35. SQL > Select * from employee where department_id IN (select department_id from
department where name=’SALES’)
36. SQL > Select * from employee where job_id in (select job_id from job where
function=’CLERK’
37. SQL > Select * from employee where department_id=(select department_id from
department where location_id=(select location_id from location where regional_group=’New
York’))
38. SQL > Select * from employee where department_id=(select department_id from
department where name=’SALES’ group by department_id)
39. SQL > Update employee set salary=salary*10/100 wehre job_id=(select job_id from job
where function=’CLERK’)
40. SQL > delete from employee where department_id=(select department_id from department
where name=’ACCOUNTING’)
41. SQL > Select * from employee where salary=(select max(salary) from employee where
salary <(select max(salary) from employee))
42. SQL > Select distinct e.salary from employee where & no-1=(select count(distinct salary)
from employee where sal>e.salary)
43. SQL > Select * from employee where salary > all (Select salary from employee where
department_id=30)
44. SQL > Select * from employee where salary > any (Select salary from employee where
department_id=30)
45. SQL > Select employee_id, last_name, department_id from employee e where not exists
(select department_id from department d where d.department_id=e.department_id)
46. SQL > Select name from department d where not exists (select last_name from employee e
where d.department_id=e.department_id)
47. SQL > Select employee_id, last_name, salary, department_id from employee e where salary
> (select avg(salary) from employee where department_id=e.department_id)
48. SQL > Select employee_id, last_name, name from employee e, department d where
e.department_id=d.department_id
49. SQL > Select employee_id, last_name, function from employee e, job j where
e.job_id=j.job_id
ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT
Compiled By:- Melaku Tewoldebrehan(BSc.) Page 6
50. SQL > Select employee_id, last_name, name, regional_group from employee e, department
d, location l where e.department_id=d.department_id and d.location_id=l.location_id
51. SQL > Select name, count(*) from employee e, department d where
d.department_id=e.department_id group by name
52. SQL > Select name, count(*) from employee e, department d where
d.department_id=e.department_id group by name having name=’SALES’
53. SQL > Select name, count(*) from employee e, department d where
d.department_id=e.department_id group by name having count (*)>=5 order by name
54. SQL > Select function, count(*) from employee e, job j where j.job_id=e.job_id group by
function
55. SQL > Select regional_group, count(*) from employee e, department d, location l where
e.department_id=d.department_id and d.location_id=l.location_id and
regional_group=’NEW YORK’ group by regional_group
56. SQL > Select employee_id, last_name, grade_id from employee e, salary_grade s where
salary between lower_bound and upper_bound order by last_name
57. SQL > Select grade_id, count(*) from employee e, salary_grade s where salary between
lower_bound and upper_bound group by grade_id order by grade_id desc
58. SQL > Select grade_id, count(*) from employee e, salary_grade s where salary between
lower_bound and upper_bound and lower_bound>=2000 and lower_bound<=5000 group
by grade_id order by grade_id desc
59. SQL > Select e.last_name emp_name, m.last_name, mgr_name from employee e,
employee m where e.manager_id=m.employee_id
60. SQL > Select e.last_name emp_name, e.salary emp_salary, m.last_name, mgr_name,
m.salary mgr_salary from employee e, employee m where e.manager_id=m.employee_id
and m.salary<e.salary
61. SQL > Select m.manager_id, count(*) from employee e, employee m where
e.employee_id=m.manager_id group by m.manager_id
62. SQL > Select last_name, d.department_id, d.name from employee e, department d where
e.department_id(+)=d.department_id
63. SQL > Select last_name, d.department_id, d.name from employee e, department d where
e.department_id(+)=d.department_id and d.department_idin (select department_id from
department where name IN (‘SALES’,’OPERATIONS’))
64. SQL > Select function from job where job_id in (Select job_id from employee where
department_id=(select department_id from department where name=’SALES’)) union
Select function from job where job_id in (Select job_id from employee where
department_id=(select department_id from department where name=’ACCOUNTING’))
65. SQL > Select function from job where job_id in (Select job_id from employee where
department_id=(select department_id from department where name=’SALES’)) union all
Select function from job where job_id in (Select job_id from employee where
department_id=(select department_id from department where name=’ACCOUNTING’))
66. SQL > Select function from job where job_id in (Select job_id from employee where
department_id=(select department_id from department where name=’RESEARCH’))
intersect Select function from job where job_id in (Select job_id from employee where
department_id=(select department_id from department where name=’ACCOUNTING’))
order by function

More Related Content

What's hot

Sql queires
Sql queiresSql queires
Sql queires
MohitKumar1985
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
vijaybusu
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
Mohd Tousif
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
Md Mudassir
 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related Queries
Mohammad Imam Hossain
 
Q on subquery
Q on subqueryQ on subquery
Q on subquery
ABHIJEET KHIRE
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
AnjaliJain167
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
Rayhan Chowdhury
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
Nexus
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handoutsjhe04
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
Dhananjay Goel
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 

What's hot (20)

SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
Sql queires
Sql queiresSql queires
Sql queires
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 
SQL practice questions set
SQL practice questions setSQL practice questions set
SQL practice questions set
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related Queries
 
Q on subquery
Q on subqueryQ on subquery
Q on subquery
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
SQL commands
SQL commandsSQL commands
SQL commands
 

Viewers also liked

Sql interview question part 9
Sql interview question part 9Sql interview question part 9
Sql interview question part 9
kaashiv1
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
nagesh Rao
 
Sql interview question part 8
Sql interview question part 8Sql interview question part 8
Sql interview question part 8
kaashiv1
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements Tutorial
ProdigyView
 
Oracle SQL Interview Questions for Freshers
Oracle SQL Interview Questions for FreshersOracle SQL Interview Questions for Freshers
Oracle SQL Interview Questions for Freshers
DTecH It Education
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12c
Nelson Calero
 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
Amit Kumar Singh
 
Sql interview questions and answers
Sql interview questions and  answersSql interview questions and  answers
Sql interview questions and answers
sheibansari
 
Oracle Complete Interview Questions
Oracle Complete Interview QuestionsOracle Complete Interview Questions
Oracle Complete Interview Questions
Sandeep Sharma IIMK Smart City,IoT,Bigdata,Cloud,BI,DW
 
Steering system 7
Steering system 7Steering system 7
Steering system 7
Kanhaiyya Patil
 
100 sql queries
100 sql queries100 sql queries
100 sql queries
Srinimf-Slides
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manualmaha tce
 
Steering geometry 8
Steering geometry 8Steering geometry 8
Steering geometry 8
Kanhaiyya Patil
 
DBMS an Example
DBMS an ExampleDBMS an Example
DBMS an Example
Dr. C.V. Suresh Babu
 
MySQL
MySQLMySQL

Viewers also liked (20)

Sql interview question part 9
Sql interview question part 9Sql interview question part 9
Sql interview question part 9
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
 
Sql interview question part 8
Sql interview question part 8Sql interview question part 8
Sql interview question part 8
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements Tutorial
 
Chapter2 j2ee
Chapter2 j2eeChapter2 j2ee
Chapter2 j2ee
 
Sql basics 2
Sql basics   2Sql basics   2
Sql basics 2
 
Oracle SQL Interview Questions for Freshers
Oracle SQL Interview Questions for FreshersOracle SQL Interview Questions for Freshers
Oracle SQL Interview Questions for Freshers
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12c
 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
 
Sql interview questions and answers
Sql interview questions and  answersSql interview questions and  answers
Sql interview questions and answers
 
Oracle Complete Interview Questions
Oracle Complete Interview QuestionsOracle Complete Interview Questions
Oracle Complete Interview Questions
 
Steering system 7
Steering system 7Steering system 7
Steering system 7
 
Sql queries
Sql queriesSql queries
Sql queries
 
100 sql queries
100 sql queries100 sql queries
100 sql queries
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
Steering geometry 8
Steering geometry 8Steering geometry 8
Steering geometry 8
 
DBMS an Example
DBMS an ExampleDBMS an Example
DBMS an Example
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
MySQL
MySQLMySQL
MySQL
 
Word Chapter 04
Word Chapter 04Word Chapter 04
Word Chapter 04
 

Similar to Sql queries questions and answers

Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1
Mohd Tousif
 
Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015
dezyneecole
 
Nikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd YearNikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd Year
dezyneecole
 
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole CollegeDivyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
dezyneecole
 
Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015
dezyneecole
 
Vijay Kumar
Vijay KumarVijay Kumar
Vijay Kumar
dezyneecole
 
Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015
dezyneecole
 
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
 Apurv Gupta, BCA ,Final year , Dezyne E'cole College Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
dezyneecole
 
Sql task
Sql taskSql task
Sql task
Nawaz Sk
 
SQL case study Analysis PPT by Radhika Kashidd
SQL case study Analysis PPT by Radhika KashiddSQL case study Analysis PPT by Radhika Kashidd
SQL case study Analysis PPT by Radhika Kashidd
radhikakashid25
 
Pooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer ApplicationPooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer Application
dezyneecole
 
Sql task answers
Sql task answersSql task answers
Sql task answers
Nawaz Sk
 
Ravi querys 425
Ravi querys  425Ravi querys  425
Ravi querys 425
Sorakayala Ashok
 
Pooja Jain
Pooja JainPooja Jain
Pooja Jain
dezyneecole
 
sql qn.docx
sql qn.docxsql qn.docx
sql qn.docx
HarshalMathur
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 
Sql query file work
Sql query file workSql query file work
Sql query file work
Anjaan Gajendra
 
Dump Answers
Dump AnswersDump Answers
Dump Answers
sailesh kushwaha
 
Sql assignment 4
Sql assignment 4Sql assignment 4
Sql assignment 4
sateesh maraju
 
SQL Practice Question set
SQL Practice Question set SQL Practice Question set
SQL Practice Question set
Mohd Tousif
 

Similar to Sql queries questions and answers (20)

Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1Introduction to Databases - Assignment_1
Introduction to Databases - Assignment_1
 
Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015Priyanka Bhatia.BCA Final year 2015
Priyanka Bhatia.BCA Final year 2015
 
Nikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd YearNikhil Khandelwal BCA 3rd Year
Nikhil Khandelwal BCA 3rd Year
 
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole CollegeDivyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
 
Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015Simran kaur,BCA Final Year 2015
Simran kaur,BCA Final Year 2015
 
Vijay Kumar
Vijay KumarVijay Kumar
Vijay Kumar
 
Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015Vishwajeet Sikhwal ,BCA,Final Year 2015
Vishwajeet Sikhwal ,BCA,Final Year 2015
 
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
 Apurv Gupta, BCA ,Final year , Dezyne E'cole College Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
 
Sql task
Sql taskSql task
Sql task
 
SQL case study Analysis PPT by Radhika Kashidd
SQL case study Analysis PPT by Radhika KashiddSQL case study Analysis PPT by Radhika Kashidd
SQL case study Analysis PPT by Radhika Kashidd
 
Pooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer ApplicationPooja Bijawat,Bachelor Degree in Computer Application
Pooja Bijawat,Bachelor Degree in Computer Application
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
Ravi querys 425
Ravi querys  425Ravi querys  425
Ravi querys 425
 
Pooja Jain
Pooja JainPooja Jain
Pooja Jain
 
sql qn.docx
sql qn.docxsql qn.docx
sql qn.docx
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 
Sql query file work
Sql query file workSql query file work
Sql query file work
 
Dump Answers
Dump AnswersDump Answers
Dump Answers
 
Sql assignment 4
Sql assignment 4Sql assignment 4
Sql assignment 4
 
SQL Practice Question set
SQL Practice Question set SQL Practice Question set
SQL Practice Question set
 

Recently uploaded

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 

Recently uploaded (20)

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 

Sql queries questions and answers

  • 1. ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT Compiled By:- Melaku Tewoldebrehan(BSc.) Page 1 Worksheet Prepared For Database Administration Trainees SQL Queries And Answeres Create the following Tables: LOCATION Location_ID Regional_Group 122 NEW YORK 123 DALLAS 124 CHICAGO 167 BOSTON DEPARTMENT Department_ID Name Location_ID 10 ACCOUNTING 122 20 RESEARCH 124 30 SALES 123 40 OPERATIONS 167 JOB Job_ID Function 667 CLERK 668 STAFF 669 ANALYST 670 SALESPERSON 671 MANAGER 672 PRESIDENT EMPLOYEE EMPL OYEE _ID LAST_N AME FIRST _NAM E MID DLE _NA ME JOB_I D MANA GER_I D HIREDATE SALAR Y COMM DEPA RTME NT_ID 7369 SMITH JOHN Q 667 7902 17-DEC-84 800 NULL 20 7499 ALLEN KEVIN J 670 7698 20-FEB-85 1600 300 30 7505 DOYLE JEAN K 671 7839 04-APR-85 2850 NULL 30 7506 DENNIS LYNN S 671 7839 15-MAY-85 2750 NULL 30 7507 BAKER LESLI E D 671 7839 10-JUN-85 2200 NULL 40 7521 WARK CYNT HIA D 670 7698 22-FEB-85 1250 500 30 Queries based on the above tables:
  • 2. ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT Compiled By:- Melaku Tewoldebrehan(BSc.) Page 2 Simple Queries: 1. List all the employee details 2. List all the department details 3. List all job details 4. List all the locations 5. List out first name,last name,salary, commission for all employees 6. List out employee_id,last name,department id for all employees and rename employee id as “ID of the employee”, last name as “Name of the employee”, department id as “department ID” 7. List out the employees anuual salary with their names only. Where Conditions: 8. List the details about “SMITH” 9. List out the employees who are working in department 20 10. List out the employees who are earning salary between 3000 and 4500 11. List out the employees who are working in department 10 or 20 12. Find out the employees who are not working in department 10 or 30 13. List out the employees whose name starts with “S” 14. List out the employees whose name start with “S” and end with “H” 15. List out the employees whose name length is 4 and start with “S” 16. List out the employees who are working in department 10 and draw the salaries more than 3500 17. list out the employees who are not receiving commission. Order By Clause: 18. List out the employee id, last name in ascending order based on the employee id. 19. List out the employee id, name in descending order based on salary column 20. list out the employee details according to their last_name in ascending order and salaries in descending order 21. list out the employee details according to their last_name in ascending order and then on department_id in descending order. Group By & Having Clause: 22. How many employees who are working in different departments wise in the organization 23. List out the department wise maximum salary, minimum salary, average salary of the employees 24. List out the job wise maximum salary, minimum salary, average salaries of the employees. 25. List out the no.of employees joined in every month in ascending order. 26. List out the no.of employees for each month and year, in the ascending order based on the year, month. 27. List out the department id having atleast four employees. 28. How many employees in January month. 29. How many employees who are joined in January or September month. 30. How many employees who are joined in 1985. 31. How many employees joined each month in 1985. 32. How many employees who are joined in March 1985. 33. Which is the department id, having greater than or equal to 3 employees joined in April 1985. Sub-Queries
  • 3. ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT Compiled By:- Melaku Tewoldebrehan(BSc.) Page 3 34. Display the employee who got the maximum salary. 35. Display the employees who are working in Sales department 36. Display the employees who are working as “Clerk”. 37. Display the employees who are working in “New York” 38. Find out no.of employees working in “Sales” department. 39. Update the employees salaries, who are working as Clerk on the basis of 10%. 40. Delete the employees who are working in accounting department. 41. Display the second highest salary drawing employee details. 42. Display the Nth highest salary drawing employee details Sub-Query operators: (ALL,ANY,SOME,EXISTS) 43. List out the employees who earn more than every employee in department 30. 44. List out the employees who earn more than the lowest salary in department 30. 45. Find out whose department has not employees. 46. Find out which department does not have any employees. Co-Related Sub Queries: 47.Find out the employees who earn greater than the average salary for their department. Joins Simple join 48.List our employees with their department names 49.Display employees with their designations (jobs) 50.Display the employees with their department name and regional groups. 51.How many employees who are working in different departments and display with department name. 52.How many employees who are working in sales department. 53.Which is the department having greater than or equal to 5 employees and display the department names in ascending order. 54.How many jobs in the organization with designations. 55.How many employees working in “New York”. Non – Equi Join: 56.Display employee details with salary grades. 57.List out the no. of employees on grade wise. 58.Display the employ salary grades and no. of employees between 2000 to 5000 range of salary. Self Join: 59.Display the employee details with their manager names. 60.Display the employee details who earn more than their managers salaries. 61.Show the no. of employees working under every manager. Outer Join: 61.Display employee details with all departments. 62.Display all employees in sales or operation departments. Set Operators: 63.List out the distinct jobs in Sales and Accounting Departments. 64.List out the ALL jobs in Sales and Accounting Departments. 65.List out the common jobs in Research and Accounting Departments in ascending order.
  • 4. ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT Compiled By:- Melaku Tewoldebrehan(BSc.) Page 4 Answers 1. SQL > Select * from employee; 2. SQL > Select * from department; 3. SQL > Select * from job; 4. SQL > Select * from loc; 5. SQL > Select first_name, last_name, salary, commission from employee; 6. SQL > Select employee_id “id of the employee”, last_name “name", department id as “department id” from employee; 7. SQL > Select last_name, salary*12 “annual salary” from employee 8. SQL > Select * from employee where last_name=’SMITH’; 9. SQL > Select * from employee where department_id=20 10. SQL > Select * from employee where salary between 3000 and 4500 11. SQL > Select * from employee where department_id in (20,30) 12. SQL > Select last_name, salary, commission, department_id from employee where department_id not in (10,30) 13. SQL > Select * from employee where last_name like ‘S%’ 14. SQL > Select * from employee where last_name like ‘S%H’ 15. SQL > Select * from employee where last_name like ‘S___’ 16. SQL > Select * from employee where department_id=10 and salary>3500 17. SQL > Select * from employee where commission is Null 18. SQL > Select employee_id, last_name from employee order by employee_id 19. SQL > Select employee_id, last_name, salary from employee order by salary desc 20. SQL > Select employee_id, last_name, salary from employee order by last_name, salary desc 21. SQL > Select employee_id, last_name, salary from employee order by last_name, department_id desc 22. SQL > Select department_id, count(*), from employee group by department_id 23. SQL > Select department_id, count(*), max(salary), min(salary), avg(salary) from employee group by department_id 24. SQL > Select job_id, count(*), max(salary), min(salary), avg(salary) from employee group by job_id 25. SQL > Select to_char(hire_date,’month’)month, count(*) from employee group by to_char(hire_date,’month’) order by month 26. SQL > Select to_char(hire_date,’yyyy’) Year, to_char(hire_date,’mon’) Month, count(*) “No. of employees” from employee group by to_char(hire_date,’yyyy’), to_char(hire_date,’mon’) 27. SQL > Select department_id, count(*) from employee group by department_id having count(*)>=4 28. SQL > Select to_char(hire_date,’mon’) month, count(*) from employee group by to_char(hire_date,’mon’) having to_char(hire_date,’mon’)=’jan’
  • 5. ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT Compiled By:- Melaku Tewoldebrehan(BSc.) Page 5 29. SQL > Select to_char(hire_date,’mon’) month, count(*) from employee group by to_char(hire_date,’mon’) having to_char(hire_date,’mon’) in (‘jan’,’sep’) 30. SQL > Select to_char(hire_date,’yyyy’) Year, count(*) from employee group by to_char(hire_date,’yyyy’) having to_char(hire_date,’yyyy’)=1985 31. SQL > Select to_char(hire_date,’yyyy’)Year, to_char(hire_date,’mon’) Month, count(*) “No. of employees” from employee where to_char(hire_date,’yyyy’)=1985 group by to_char(hire_date,’yyyy’),to_char(hire_date,’mon’) 32. SQL > Select to_char(hire_date,’yyyy’)Year, to_char(hire_date,’mon’) Month, count(*) “No. of employees” from employee where to_char(hire_date,’yyyy’)=1985 and to_char(hire_date,’mon’)=’mar’ group by to_char(hire_date,’yyyy’),to_char(hire_date,’mon’) 33. SQL > Select department_id, count(*) “No. of employees” from employee where to_char(hire_date,’yyyy’)=1985 and to_char(hire_date,’mon’)=’apr’ group by to_char(hire_date,’yyyy’), to_char(hire_date,’mon’), department_id having count(*)>=3 34. SQL > Select * from employee where salary=(select max(salary) from employee) 35. SQL > Select * from employee where department_id IN (select department_id from department where name=’SALES’) 36. SQL > Select * from employee where job_id in (select job_id from job where function=’CLERK’ 37. SQL > Select * from employee where department_id=(select department_id from department where location_id=(select location_id from location where regional_group=’New York’)) 38. SQL > Select * from employee where department_id=(select department_id from department where name=’SALES’ group by department_id) 39. SQL > Update employee set salary=salary*10/100 wehre job_id=(select job_id from job where function=’CLERK’) 40. SQL > delete from employee where department_id=(select department_id from department where name=’ACCOUNTING’) 41. SQL > Select * from employee where salary=(select max(salary) from employee where salary <(select max(salary) from employee)) 42. SQL > Select distinct e.salary from employee where & no-1=(select count(distinct salary) from employee where sal>e.salary) 43. SQL > Select * from employee where salary > all (Select salary from employee where department_id=30) 44. SQL > Select * from employee where salary > any (Select salary from employee where department_id=30) 45. SQL > Select employee_id, last_name, department_id from employee e where not exists (select department_id from department d where d.department_id=e.department_id) 46. SQL > Select name from department d where not exists (select last_name from employee e where d.department_id=e.department_id) 47. SQL > Select employee_id, last_name, salary, department_id from employee e where salary > (select avg(salary) from employee where department_id=e.department_id) 48. SQL > Select employee_id, last_name, name from employee e, department d where e.department_id=d.department_id 49. SQL > Select employee_id, last_name, function from employee e, job j where e.job_id=j.job_id
  • 6. ADDIS ABABA TEGEBARE-ID POLY TECHNIQUE COLLEGE DEPARTMENT OF ICT Compiled By:- Melaku Tewoldebrehan(BSc.) Page 6 50. SQL > Select employee_id, last_name, name, regional_group from employee e, department d, location l where e.department_id=d.department_id and d.location_id=l.location_id 51. SQL > Select name, count(*) from employee e, department d where d.department_id=e.department_id group by name 52. SQL > Select name, count(*) from employee e, department d where d.department_id=e.department_id group by name having name=’SALES’ 53. SQL > Select name, count(*) from employee e, department d where d.department_id=e.department_id group by name having count (*)>=5 order by name 54. SQL > Select function, count(*) from employee e, job j where j.job_id=e.job_id group by function 55. SQL > Select regional_group, count(*) from employee e, department d, location l where e.department_id=d.department_id and d.location_id=l.location_id and regional_group=’NEW YORK’ group by regional_group 56. SQL > Select employee_id, last_name, grade_id from employee e, salary_grade s where salary between lower_bound and upper_bound order by last_name 57. SQL > Select grade_id, count(*) from employee e, salary_grade s where salary between lower_bound and upper_bound group by grade_id order by grade_id desc 58. SQL > Select grade_id, count(*) from employee e, salary_grade s where salary between lower_bound and upper_bound and lower_bound>=2000 and lower_bound<=5000 group by grade_id order by grade_id desc 59. SQL > Select e.last_name emp_name, m.last_name, mgr_name from employee e, employee m where e.manager_id=m.employee_id 60. SQL > Select e.last_name emp_name, e.salary emp_salary, m.last_name, mgr_name, m.salary mgr_salary from employee e, employee m where e.manager_id=m.employee_id and m.salary<e.salary 61. SQL > Select m.manager_id, count(*) from employee e, employee m where e.employee_id=m.manager_id group by m.manager_id 62. SQL > Select last_name, d.department_id, d.name from employee e, department d where e.department_id(+)=d.department_id 63. SQL > Select last_name, d.department_id, d.name from employee e, department d where e.department_id(+)=d.department_id and d.department_idin (select department_id from department where name IN (‘SALES’,’OPERATIONS’)) 64. SQL > Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’SALES’)) union Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’ACCOUNTING’)) 65. SQL > Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’SALES’)) union all Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’ACCOUNTING’)) 66. SQL > Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’RESEARCH’)) intersect Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’ACCOUNTING’)) order by function