Sistem Basis Data SQL 71130121
Sistem Basis Data SQL 71130121
Nama Penyusun :
Alvin Tanjung
( 71130121 )
Djunaidi
Universitas
Duta Wacana
Kristen
Yogyakarta
Tampilkan department ID, nama departemen, dan jumlah karyawan yang bekerja di
departemen itu.
select d.department_id, d.department_name, count(e.employee_id)
from hr.employees e, hr.departments d
where e.department_id=d.department_id
group by d.department_id, d.department_name
e. Tampilkan employee id, nama employee, department id, nama department, dan rata-rata
penghasilannya. Dimana department ID diatas 100.
select e.employee_id, e.first_name, d.department_id,
d.department_name, avg(e.salary)
from hr.employees e, hr.departments d
where e.department_id=d.department_id and e.department_id >100
group by e.employee_id, e.first_name, d.department_id,
d.department_name
2. Himpunan
a. Tampilkan locations ID antara table locations dengan departmnets
select location_id
from hr.locations
union
select location_id
from hr.departments
4. Natural Join
Tampilkan employee_ID , first_name, job_title. Dimana job_titlenya adalah seorang
programmer
select employee_id, first_name, job_title
from hr.employees NATURAL JOIN hr.jobs
where job_title LIKE 'Programmer'
8
5. SubQuery
a. Seorang ingin mengetahui data diri pegawainya, tetapi ia hanya ingin mengetahui
pegawai dengan gaji lebih dari gaji temannya. Dimana ID temanya = 103.
Tampilkan employee_id, full_name, email
select employee_id, first_name || ' ' || last_name full_name, email
from hr.employees
where salary > (
select salary
from hr.employees
where employee_id = 103)
c. Tampilkan email dan phone_number, dari table employees. Dimana employee_id lebih
besar dari employee_id valli.
select email, phone_number
from hr.employees
where employee_id > (
select employee_id
from hr.employees
where first_name = 'Valli')
10
d. Tampilkan nama city dari table locations, dimana memiliki location_id lebih besar dari
locations_id city Toronto.
select city
from hr.locations
where location_id > (
select location_id
from hr.locations
where city = 'Toronto')
11
e.
Tampilkan tanggal bekerja pegawai, dimana employee_id lebih kecil dari employee_id
Diana.
select hire_date
from hr.employees
where employee_id < (
select employee_id
from hr.employees
where first_name = 'Diana')
12