SELECT last_name,e.department_id,
department_name
FROM employees e
LEFT OUTER JOIN departments d
ON e.department_id=d.department_id;
SELECT job_id, location_id
FROM employees e
JOIN departments d
ON e.department_id = d.department_id
WHERE e.department_id = 90;
SELECT last_name , job_id , e.department_id , department_name
FROM employees e, departments d, locations l
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id
AND city = 'Toronto';
SELECT department_name, street_address, last_name, job_id, salary
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.`location_id` = l.location_id
WHERE department_name = 'Executive'
SELECT employee_id,last_name,department_name
FROM employees e,departments d
WHERE e.department_id = d.`department_id`
AND d.`department_name` IN ('Sales','IT');
#第七章聚合函数
#1 常见的聚合函数
#1.1 AVG / SUM 只适用于数值类型的字段(或变量)
SELECT AVG(salary),SUM(salary)
FROM employees;
SELECT AVG(last_name),SUM(last_name),AVG(hire_date),SUM(hire_date)
FROM employees;
#1.2 MAX / MIN 适用于数值类型、字符串类型、日期时间类型的字段
SELECT MAX(salary),MIN(salary)
FROM employees;