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

Trabalho Join BD

The document contains a series of SQL queries related to employee data, including details such as last names, employee IDs, department names, job titles, and locations. It also includes conditions for filtering results based on criteria like commission percentage, manager IDs, and hire dates. The queries demonstrate various SQL operations such as joins, distinct selections, and conditional statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Trabalho Join BD

The document contains a series of SQL queries related to employee data, including details such as last names, employee IDs, department names, job titles, and locations. It also includes conditions for filtering results based on criteria like commission percentage, manager IDs, and hire dates. The queries demonstrate various SQL operations such as joins, distinct selections, and conditional statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Nome: Gabriel Martins Costa

1.
SELECT e.LAST_NAME,
e.EMPLOYEE_ID,
d.DEPARTMENT_NAME
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d ON e.DEPARTMENT_ID =
d.DEPARTMENT_ID; 2.
SELECT DISTINCT j.JOB_TITLE,
l.CITY
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
INNER JOIN LOCATIONS l ON d.LOCATION_ID = l.LOCATION_ID
INNER JOIN JOBS j ON e.JOB_ID = j.JOB_ID
WHERE d.DEPARTMENT_ID = 80;

3.
SELECT e.LAST_NAME,
d.DEPARTMENT_NAME,
l.STREET_ADDRESS,
l.CITY
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
INNER JOIN LOCATIONS l ON d.LOCATION_ID = l.LOCATION_ID
WHERE e.COMMISSION_PCT IS NOT NULL;

4.
SELECT e.LAST_NAME,
d.DEPARTMENT_NAME
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.LAST_NAME LIKE '%a%';

5.
SELECT e.LAST_NAME,
e.JOB_ID,
e.PHONE_NUMBER,
d.DEPARTMENT_NAME
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
INNER JOIN LOCATIONS l ON d.LOCATION_ID = l.LOCATION_ID
WHERE l.CITY = 'Toronto';

6.
SELECT e1.LAST_NAME AS "Sobrenome do empregado",
e1.EMPLOYEE_ID AS "ID do empregado",
e2.LAST_NAME AS "Sobrenome do Gerente",
e2.EMPLOYEE_ID AS "ID do Gerente"
FROM EMPLOYEES e1
LEFT JOIN EMPLOYEES e2 ON e1.MANAGER_ID =
e2.EMPLOYEE_ID; 7.
SELECT e.LAST_NAME,
e.EMPLOYEE_ID,
e.MANAGER_ID
FROM EMPLOYEES e
WHERE e.MANAGER_ID IS NULL
OR e.LAST_NAME = 'King';
8.
SELECT f.LAST_NAME AS Sobrenome_Funcionario,
f.DEPARTMENT_ID AS Numero_Departamento,
e.LAST_NAME AS Colega_Sobrenome,
e.DEPARTMENT_ID AS Colega_Numero_Departamento
FROM EMPLOYEES f
INNER JOIN EMPLOYEES e ON f.DEPARTMENT_ID = e.DEPARTMENT_ID
WHERE f.EMPLOYEE_ID = 100
AND f.EMPLOYEE_ID <> e.EMPLOYEE_ID;
9.
SELECT e.LAST_NAME,
j.JOB_TITLE,
d.DEPARTMENT_NAME,
e.SALARY,
CASE
WHEN e.SALARY BETWEEN j.MIN_SALARY AND j.MAX_SALARY THEN 'Está
no alcance'
ELSE ‘Fora de alcance’
END AS Salary_Range
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
INNER JOIN JOBS j ON e.JOB_ID = j.JOB_ID;
10.
SELECT LAST_NAME,
HIRE_DATE
FROM EMPLOYEES
WHERE HIRE_DATE > (
SELECT HIRE_DATE
FROM EMPLOYEES
WHERE LAST_NAME = 'Davies'
);

You might also like