Sie sind auf Seite 1von 3

select employee_id, last_name, salary, NVL(commission_pct,'No comm') from employ

ees;
select employee_id, last_name, salary, NVL2(commission_pct,commission_pct,'1111'
) from employees;(to use nvl2)
select length(first_name),length(last_name) from employees;
select length(first_name),length(last_name),nullif (length(first_name),length(la
st_name)) from employees;
select commission_pct,manager_id,salary, from employees;
select commission_pct,manager_id,salary,coalesce(commission_pct,manager_id,salar
y) as coal from employees; (to use for the checking the not null values)
CASE and decode
select salary, case(salary) when 10000 then 'c' when 12000 then 'b' when 24000 t
hen 'a' else 'd' end as grade from employees; (data type of all values must be s
ame in all conditions)
select salary, decode(salary,10000,'a',12000,'b',24000,'c','d') grade from emplo
yees; ()
select salary, case when salary >= 10000 then 'A' when salary < 10000 then 'B' e
lse 'C' end as grade from employees; (using the condition in the case using iden
tifier with values)
================================================
chapter 4 ()
================================================
select department_id, sum(salary) from employees group by department_id order by
department_id;
select department_id,job_id , sum(salary),count(*) from employees group by depar
tment_id, job_id order by department_id;
select department_id, sum(salary) from employees group by department_id having s
um(salary)>10000 order by 1;
--------------rollup (extensation of group by ) (display n and n+1)
--------------select department_id,job_id, sum(salary) from employees group by rollup (departm
ent_id,job_id) order by department_id;
--------------cube ()
--------------select department_id,job_id, sum(salary) from employees group by cube(department
_id,job_id) order by department_id;
========================
chepter 5 displaying
========================
1) cartesion (select * from regions, countries)
2) selection
3) projection
select employee_id, last_name, salary, e.department_id, department_name from emp
loyees e, departments d where e.department_id = d.department_id
select employee_id, last_name, salary, e.department_id, department_name from emp

loyees e join departments d on e.department_id = d.department_id


-----------------cross join
-----------------select * from regions cross join countries;
select r.region_id,region_name, country_id, country_name from regions r cross jo
in countries c;
-----------------nature join (chk the data, colum name, colum data type then display)
-----------------select region_id,region_name, country_id, country_name from regions natural join
countries;
-----------------nature join (chk the data, colum name, colum data type then display)
-----------------select region_id,region_name, country_id, country_name from regions using join c
ountries (regions_id);
select region_id,region_name, country_id, country_name from regions join countri
es using (region_id);
-----------------self join
-----------------select e.employee_id, e.last_name, m.employee_id, m.last_name from employees e ,
employees m where e.manager_id = m.employee_id;
select e.employee_id, e.last_name, m.employee_id, m.last_name from employees e j
oin employees m on e.manager_id = m.employee_id;
-----------------old outer join
-----------------select employee_id, last_name, salary, e.department_id, department_name from emp
loyees e, departments d where e.department_id = d.department_id(+);
-----------------outer join
-----------------select employee_id, last_name, salary, e.department_id, department_name from emp
loyees e, departments d where e.department_id = d.department_id(+);
select employee_id, last_name, salary, d.department_id, department_name, city fr
om employees e, departments d, locations l where d.department_id=e.department_id
and l.location_id=d.location_id ;
select employee_id, last_name, salary, d.department_id, department_name, city fr
om employees e join departments d on d.department_id=e.department_id join locati
ons l on l.location_id=d.location_id ;
select * from employees e full outer join departments d on e.department_id = d.d
epartment_id order by d.department_id;
=================================
lession 6 subquery
=================================
simple
correated
select * from employees where salary > (select salary from employees where last_

name='Abel');
select * from employees where department_id = (select department_id from employe
es where employee_id=104) and employee_id <>104;
select * from employees where manager_id = (select manager_id from employees whe
re employee_id=118);
select * from employees where employee_id in (select manager_id from employees);
select * from employees where employee_id not in (select manager_id from employe
es where manager_id is not null);

(interview question)
select * from employees e, departments d where e.department_id(+) = d.department
_id(+)order by d.department_id;
ORA-01468: a predicate may reference only one outer-joined table

select r.region_id,region_name, country_id, country_name from regions r join cou


ntries c on r.region_id=c.region_id;
order of the statement
(I) from
(II) where
(III) group by
(IV) select
(V) having
(VI) order by
hitesh.dhawdle@gmail.com

Das könnte Ihnen auch gefallen