Sunteți pe pagina 1din 2

Amelia Shabrina

6701140139
PIS-14-06

Jawaban Tugas Akhir Dasar SQL : NVL dan JOIN

1. SELECT m.first_name atasan, e.phone_number, e.email, e.salary


FROM employees e JOIN employees m
ON(e.manager_id = m.employee_id)
ORDER BY m.first_name asc;
2. SELECT j.job_title, e.first_name, SUM(e.employee_id) jumlah_pegawai
FROM employees e JOIN jobs j
ON (e.job_id = j.job_id)
WHERE e.first_name LIKE 'A%'
GROUP BY j.job_title,e.first_name
ORDER BY sum(e.employee_id) desc;
3. SELECT j.job_title as "Nama Pekerjaan", AVG(e.salary) as " Rata -Rata Gaji"
FROM jobs j join employees e
ON (j.job_id = e.job_id)
GROUP BY job_title;
4. SELECT c.country_name, e.first_name||' '||e.last_name as "Nama
Lengkap",avg(e.salary)
FROM employees e join departments d
ON (e.department_id = d.department_id)
JOIN locations l
ON (d.location_id = l.location_id)
JOIN countries c
ON (l.country_id = c.country_id)
WHERE length(e.first_name||' '||e.last_name)>5
HAVING avg(e.salary)>5000
GROUP BY c.country_name, e.first_name||' '||e.last_name
ORDER by e.first_name||' '||e.last_name asc;
5. SELECT last_name, salary,
CASE WHEN salary< 5000 THEN 'Low' WHEN salary< 10000 THEN 'Medium' WHEN
salary< 20000 THEN 'Good'
END "Keterangan Gaji"
FROM employees;
6. select e.last_name, l.city, case when ((jh.end_date – jh.start_date) / 365) < 5 then ‘5
tahun bekerja’ when ((jh.end_date – jh.start_date) / 365) >= 5 then ’10 tahun bekerja’
when ((jh.end_date – jh.start_date) / 365) > 15 then ’15 tahun bekerja’ end “Awards”
from employees e join departments d on (e.department_id = d.department_id) join
locations l on (d.location_id = l.location_id) join job_history jh on (d.department_id =
jh.department_id);
a. NVL : select first_name, nvl(to_char (commission_pct),'Tidak punya Komisi')
Komisi from employees;
b. NVL2 : select first_name,nvl2 (commission_pct,to_char(commission_pct),'Tidak
punya Komisi')Komisi from employees;
c. Decode : select first_name, decode(commission_pct, null,'tidak punya
komisi',to_char(commission_pct)) komisi from employees;
d. Case : select first_name, case when commission_pct is null then 'tidak punya
komisi' else to_char(commission_pct) end "Komisi" from employees;
7. select first_name||' '||last_name as " nama lengkap",salary as "gaji lama",
case manager_id when 121 then (salary+(salary * 0.1)) when 123 then (salary+(salary *
0.17)) when 205 then (salary+(salary * 0.23))
else salary end "Gaji Baru"
from employees;

S-ar putea să vă placă și