Exercise 3 SQL Join
2026-03-09 09:59
Tags: #ADV_DBMS
Author: Duke Hsu
SQL 語句的正確順序
記住這個順序很重要:
SELECT- Selected columnsFROM- Selected tableJOIN- Connect other tableWHERE- Filtering first table dataGROUP BY- Group columnHAVING- Filtering Group resultORDER BY- Sort
- The HR manager wants to generate a report of all company locations in the United States of
America that are specifically located in the state of California. Display Location ID, Street
Address, City, State/Province and Country Name.
1 2 3 4 5 | |
- The HR Department wants to know how many company locations exist per country. Display Country Name and Total Number of Locations
1 2 3 4 5 6 | |
- The HR Department wants to generate a report listing all employees together with the department where they are assigned. Display Employee last name, Department number and Department name
1 2 3 4 5 | |
- HR wants to display all employees, even those without a depart
1 2 3 4 | |
- HR wants to know the total number of employees per department.
1 2 3 4 5 6 | |
- The HR Department wants to display the departments that have more than 5 employees. Display Department Name and Total Number of Employees. Sort the Total Number of Employees in descending order
1 2 3 4 5 6 7 | |
- The HR Department wants to know how many employees were hired after January 1, 2005, in each department.
1 2 3 4 5 6 7 8 | |
- Display Department Name and Total Number of Employees Hired After 2005. Only include departments with at least 2 such employees.
1 2 3 4 5 6 7 8 9 10 | |
- The HR Department wants a summary report showing:
- How many employees work in each department
- Only include departments located in Seattle or New York
- Display department number, department name, location city, and total employees
1 2 3 4 5 6 7 8 9 10 11 12 | |
- The HR department needs a report of employees in Toronto. Display the Last name, Job title, Department number, and the Department name for all employees who work in Toronto.
1 2 3 4 5 6 7 8 9 10 11 12 | |
- The HR Department wants a list of all departments. For each department, show Employee last name, Employee ID, Job title and Department name. Some departments may have no employees, but they should still appear in the report.
1 2 3 4 5 6 | |
-
The HR Department wants a list showing all employees and all departments.
-
Include departments even if they have no employees.
- Include employees even if they have no department assigned.
1 2 3 4 5 6 | |
- Create a report to display employees’ last name and employee number along with their manager’s last name and manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively.
1 2 3 4 5 6 7 8 9 10 11 | |