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

Group By, Having, Sub-Query Problems

The document outlines 21 tasks related to using GROUP BY, HAVING, and SUB-QUERY problems. It includes problems analyzing student and class GPA averages by semester, comparing values using DECODE, retrieving customer and program information from tables, and analyzing employee data like salaries, departments, and managers. The tasks cover a range of SQL skills like aggregation, filtering, sorting, joins, and correlated subqueries.

Uploaded by

Kenan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Group By, Having, Sub-Query Problems

The document outlines 21 tasks related to using GROUP BY, HAVING, and SUB-QUERY problems. It includes problems analyzing student and class GPA averages by semester, comparing values using DECODE, retrieving customer and program information from tables, and analyzing employee data like salaries, departments, and managers. The tasks cover a range of SQL skills like aggregation, filtering, sorting, joins, and correlated subqueries.

Uploaded by

Kenan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

WEEK-6

TASKS

GROUP BY,
HAVING,
SUB-QUERY
PROBLEMS
1 – Students with the GPA average for all semesters
2 – Classes with the GPA average for all semesters
3 – Classes with the GPA average for each semester
4 – Average of 8th class’s GPA for all semesters
5 – Average of 8th class’s GPA for each semester
6 – Students with average GPA=3 ?
7 – Classes with GPA Average for Amount of student >=3
8 – Semesters with GPA Average for all classes.
9 – Grand average with rollup
10 – Categorize people into child,teenager and adult depending on their ages
11 – Compare a parameter and value with DECODE

If p<5 then ‘smaller’ >>>> decode(sign(p-5),-1,’ smaller’) ;


If p=5 then ‘equal’ >>>> decode(p,5,’equal’) ;
If p>5 then ‘greater’ >>>> decode(sign(p-5),1,’ greater’) ;

SELECT
ENAME,
DECODE( SIGN(SAL-2000 ),1,'GREATER THAN 2000', 'SMALLER THAN 2000') SALARY
FROM EMP;
12 – List the number of old and new cars.

1999 2000

OLD CAR NEW CAR


13 – List the average of prices for old and new cars.

1999 2000

OLD CAR NEW CAR


14-Retreive the full customer name of top-10 rows. 'AAL', 'American Airlines',
ILC - Intl. Leasing Corp. NOW - Northwest Orient,
SAL - Southwest Airlines SWA - Sweptwing Airlines
USAF - United States Air Force Not Known - AIRLINE
15-Retreive PRG_ID and Customer_Id as shown on the figure below.
16-Retreive PRG_ID and amount of each customers as shown on the figure below.
17-Retreive months and total empoyees number who started to work at that month.
18-List employees ,in department 10, has salary which is less than any salary of employees in
department 30
19-List all employees who are not working in department 30 and who earn more than
all employees working in department 30:
20-List all departments that have no employees:
21-Retrieve the minimum and maximum salary of clerks for each department having
more than 1 clerk.
22-Retreive all employees with their managers.

You might also like