Sei sulla pagina 1di 5

8.1.

PRACTICE
ex 1:
1. avg
2. count
3. stddev
4. group functions
5. min
6. variance
7. sum
8. max
9. sum????

ex 2:
1.???
2. select round(avg(cost),2)
from d_events;
3. select avg(salary)
from f_staffs
where manager_id=19;
4. select sum(salary)
from f_staffs
where id in (12,9);
5. select min(salary), min(hire_date), min(last_name), max(last_name)
from employees
where department_id in(50,60);
6. un singur rand
7. se iau in considerare si valorile nule
8. 30 martie 1969
9. select avg(order_total)
from f_orders
where order_date between to_date('January 1, 2002', 'fmMonth DD, YYYY') and
to_date('December 21, 2002', 'fmMonth DD, YYYY');
10. 29-Jan-2000
11. sum
12. a-f b-t c-f d-f e-f f-f g-t

8.2. PRACTICE
ex1:
1. count
2. distinct
3. count distinct
ex2:
1. select count(title)
from d_songs; 6
2.select count(distinct loc_type)
from d_venues; 4
3. select count(song_id)
from d_track_listings; 5
select count( distinct cd_number)
from d_track_listings;4
4. select count(email)
from d_clients; 3
5. select (count(*) - count(auth_expense_amt)) "Free from limit count"
f drom_partners;
6. 4 si 3
7. select(round(avg(nvl(auth_expense_amt,100000)),2))
from d_partners;
8. a-f b-t c t d-f
9. a-f b-f c-t d-f
9.1. PRACTICE
ex1:
1. having
2. group by
ex2:
1. a-t b-f c-f d-f e-f
2. a) sELECT manager_id, avg(salary)
FROM employees
GROUP BY manager_id
having avg(salary) <16000;
b) select count(*)
from d_cds
where cd_number<93;
c) SELECT ID, MAX(ID), artist AS Artist
FROM d_songs
WHERE duration IN('3 min', '6 min', '10 min')
HAVING ID < 50
GROUP by ID,artist;
d) SELECT loc_type, rental_fee AS Fee
FROM d_venues
WHERE id <100
GROUP BY rental_fee, loc_type
ORDER BY 2;
3. SELECT track, MAX(song_id)
FROM d_track_listings
WHERE track IN ( 1, 2, 3)
group by track;
4. a-t b-f c-f
5. select max(avg(salary)), min(avg(salary))
from employees
group by department_id;
6. select avg(max(salary))
from employees
group by department_id;

9.2. PRACTICE
ex1:
1. rollup
2. cube
3. grouping sets
ex2:
1. SELECT manager_id, job_id, SUM(salary) "total salary",
GROUPING(manager_id), GROUPING(job_id)
FROM employees
GROUP BY ROLLUP(manager_id, job_id);
2. SELECT manager_id, job_id, SUM(salary) "total salary",
GROUPING(manager_id), GROUPING(job_id)
FROM employees
GROUP BY cube(manager_id, job_id);
3. SELECT department_id, manager_id, job_id, SUM(salary) "total salary",
GROUPING(department_id), GROUPING(manager_id), GROUPING(job_id)
FROM employees
GROUP BY GROUPING SETS((department_id, manager_id, job_id), (manager_id,
job_id), (department_id, manager_id));

9.3. PRACTICE
ex1:
1. union
2. to_char, to_date, to_number
3. union all
4. minus
5. intersect
ex2:
1. Union, union all, intersect, minus
2. select employee_id, job_id, hire_date,to_date(null), department_id
from employees
union
select employee_id, job_id, to_date(null),start_date, department_id
from job_history
3. select employee_id, job_id, hire_date,to_date(null), department_id
from employees
union all
select employee_id, job_id, to_date(null),start_date, department_id
from job_history
order by employee_id;
4. select distinct employee_id
from employees
minus select distinct employee_id
from job_history;
5. select distinct employee_id
from employees
intersect
select distinct employee_id
from job_history;
6. select employee_id, job_id, nvl(salary,0)
from employees
union
select employee_id, job_id, 0
from job_history;

10.1 PRACTICE
ex1:
1. outer query
2. multiple query
7. subquery
ex2:
1. sa putem folosi informatii detaliate pe care nu le cunoastem inca
2. un query intr-un query
3. select song_id
from d_play_list_items
where event_id in(select event_id from d_play_list_items where song_id=45);
4. SELECT id, name
FROM d_events
WHERE cost > (SELECT cost FROM d_events WHERE id = 100);
5. SELECT track
FROM d_track_listings
WHERE cd_number = (SELECT cd_number FROM d_cds WHERE title = 'Party Music for
All Occasions');
6. SELECT id, name
FROM d_events
WHERE theme_code = (SELECT code FROM d_themes WHERE description =
'Tropical');
7. SELECT first_name,last_name
FROM f_staffs
WHERE salary > (SELECT salary FROM f_staffs WHERE id = 12);
8. SELECT first_name,last_name
FROM f_staffs
WHERE staff_type != (SELECT staff_type FROM f_staffs WHERE first_name = 'Bob'
AND last_name ='Miller');
9. SELECT first_name,last_name
FROM employees
WHERE department_id = (SELECT department_id FROM departments WHERE
department_name = 'IT');
10. SELECT department_name
FROM departments
WHERE location_id = ( SELECT location_id FROM locations WHERE city =
'Seattle');
11. a-t b-t c-f

10.2. PRACTICE
ex1:
1. SELECT first_name, last_name
FROM EMPLOYEES
WHERE salary > (SELECT salary FROM employees WHERE last_name = 'Lorentz')
AND department_id = (SELECT department_id FROM employees WHERE last_name =
'Abel');
2. SELECT first_name, last_name
FROM EMPLOYEES
WHERE job_id = (SELECT job_id FROM employees WHERE last_name = 'Rajs')
AND hire_date > (SELECT hire_date FROM employees WHERE last_name = 'Davies')
;
3. SELECT id, name
FROM d_events
WHERE theme_code = (SELECT theme_code FROM d_events WHERE id = 100)
4. SELECT staff_type, MAX(salary)
FROM f_staffs
GROUP BY staff_type
HAVING MAX(salary) < (SELECT MAX(SALARY) FROM f_staffs WHERE staff_type =
'Cook');
5. SELECT department_id, TO_CHAR(ROUND(AVG(salary),2),'$999999.99') "Average
Salary"
FROM employees
GROUP BY department_id
HAVING AVG(salary) > ( SELECT salary from employees WHERE last_name =
'Ernst');
6. SELECT department_id, TO_CHAR(ROUND(MIN(salary),2),'$999999.99') "Minimum
Salary"
FROM employees
GROUP BY department_id
HAVING MIN(salary) > ( SELECT MIN(salary) from employees WHERE
department_id != 50);

10.3.
2. SELECT id, title, duration, artist
FROM d_songs
WHERE type_code IN ( SELECT code FROM d_types WHERE description IN ('Jazz',
'Pop'));
3. SELECT last_name
FROM employees
WHERE salary in ( SELECT MIN(salary) FROM employees GROUP BY department_id);
4. SELECT last_name
FROM f_staffs
WHERE NVL(salary,0) = ( SELECT MIN(NVL(salary,0)) FROM f_staffs);
5. a) SELECT *
FROM d_cds
WHERE TO_NUMBER(year) < ( SELECT TO_NUMBER(year) FROM d_cds where title =
'Carpe Diem');
b) SELECT last_name, salary
FROM employees
WHERE salary < ANY ( SELECT salary FROM employees where department_id =
(SELECT department_id FROM departments WHERE department_name = 'IT'));
c) SELECT title
FROM d_cds
WHERE TO_NUMBER(year) IN ( SELECT TO_NUMBER(year) FROM d_cds where title
in( 'Carpe Diem', 'Party Music for All Occasions'));
d) SELECT title, duration
FROM d_songs
WHERE TO_NUMBER(REPLACE(duration,' min','')) > ALL ( SELECT
TO_NUMBER(REPLACE(duration,' min',''))
FROM d_songs where type_code = 77);
6. a-t b-f c-f d-t e-f
7. SELECT department_id, MIN(salary)
FROM employees
GROUP BY department_id
HAVING MIN(salary) < (SELECT MIN(salary) FROM employees WHERE department_id =
50);
8. a-f b-t c-f d-t
9. ??
10. ??

10.4.
2. SELECT o.last_name, o.department_id, o.salary
FROM employees o
WHERE o.salary = (SELECT MAX(i.salary) FROM employees i WHERE
i.department_id=o.department_id);
3. SELECT o.last_name, o.department_id, o.salary
FROM employees o
WHERE o.employee_id IN (SELECT distinct i.manager_id
FROM employees i
WHERE o.manager_id= i.employee_id);
4. select job_title
from jobs
where jobs.max_salary>(select * from (SELECT MAX(max_salary)/2 FROM jobs))

Potrebbero piacerti anche