0% found this document useful (0 votes)
82 views2 pages

BD Lab5

The document contains 14 SQL queries that retrieve employee, job, department, location and other related data from database tables. The queries perform operations like filtering on job title, location, calculating aggregates and joining multiple tables.

Uploaded by

Cosmin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views2 pages

BD Lab5

The document contains 14 SQL queries that retrieve employee, job, department, location and other related data from database tables. The queries perform operations like filtering on job title, location, calculating aggregates and joining multiple tables.

Uploaded by

Cosmin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Afisati numele, numarul si numele job-ului pentru toti angajatii.

SELECT last_name, first_name,job_title,employee_id


FROM Employees e, Jobs j
WHERE e.job_id=j.job_id

2. Afisati numele, numarul si numele job-ului pentru toti angajatii cu job-ul


Programmer.

SELECT last_name,first_name, j.job_title


FROM Employees e,Jobs j
WHERE e.job_id=j.job_id AND j.job_title = 'Programmer'

3. Afisati numele angajatilor, numele departamentului �n care lucreaza si numele


jobului.

SELECT last_name,first_name,department_name,job_title
FROM Employees e,Departments d,Jobs j
WHERE e.department_id = d.department_id AND e.job_id=j.job_id

4. Scrieti o cerere care sa intoarca numele, numarul si numele departamentului si


job-ul
tuturor celor care lucreaza �n Seattle.

SELECT last_name,first_name,department_name,d.department_id,job_title,l.city
FROM Employees e,Departments d,Locations l,Jobs j
WHERE e.department_id = d.department_id AND e.job_id=j.job_id AND city='Seattle'
AND d.location_id = l.location_id;

5. Afisati toate locatiile (orasul si tara) din Europa

SELECT l.city, c.country_id, r.region_name


FROM Regions r, Locations l,Countries c
WHERE l.country_id = c.country_id AND r.region_name = 'Europe' AND c.region_id =
r.region_id

6. Afisati numele departamentelor din Canada

SELECT d.department_name,c.country_name,l.country_id
FROM Departments d, Locations l, Countries c
WHERE d.location_id = l.location_id AND c.country_name = 'Canada' AND l.country_id
= c.country_id

7. Afisati numele departamentelor, numarul de angajati si salariul mediu pentru


fiecare
departament

SELECT department_name,COUNT(employee_id), AVG(salary)


FROM Employees e,Departments d
WHERE e.department_id = d.department_id
Group by department_name

8. Gasiti care sunt numele acelor departamente �n care salariul maxim este mai mare
dacat 10000

SELECT department_name,max(salary)
FROM Employees e,Departments d
WHERE e.department_id = d.department_id
Group by department_name
Having max(salary) > 10000

9. Afisati numarul de tari care sunt inregistrate pentru fiecare regiune.

SELECT region_name,count(country_id)
FROM Countries c, Regions r
WHERE c.region_id = r.region_id
Group by region_name

10. Afisati numele job-urilor, salariul mediu pentru fiecare si nr de angajati


pentru joburile
de vanzari (Sales).

ELECT job_title, avg(salary), count(employee_id)


FROM Jobs j , Employees e
WHERE j.job_id = e.job_id and job_title like '%Sales%'
Group by job_title

11. Scrieti o interogare care afiseaza numele si job-ul angajatilor care lucreaza
�n acelasi
departament cu angajatul cu numele Luis Popp.

SELECT e1.last_name,e1.first_name,e1.department_id
FROM Employees e, Employees e1
WHERE e.department_id = e1.department_id AND e.last_name = 'Popp' AND e.first_name
= 'Luis';

12. . Scrieti o interogare care sa afiseze numele si identificatorii angajatilor


precum si
numele si identificatorul managerului caruia ii este subordonat fiecare. Etichetati
coloanele astfel: "Angajat"," Marca_ang"," Manager", " Marca_man". Salvati
interogarea intr-un script.

SELECT ang.employee_id AS marca_ang, ang.first_name AS Angajat, man.employee_id AS


marca_man,man.first_name AS Manager
FROM Employees ang, Employees man
WHERE ang.manager_id = man.manager_id

14. Creati o interogare care are ca rezultat afisarea locatiei (id si oras) si a
numelui
departamentelor. Includeti toate locatiile, chiar daca nu exista niciun departament
corespunzator.

SELECT d.department_name,d.location_id,l.city
FROM Departments d, Locations l
WHERE d.location_id = l.location_id(+)

You might also like