#where or behind HAVING:
# scalar query (single subquery)
# column subquery (multiple-row subqueries)
# subquery row (rows and columns)
Features: subquery placed in parentheses, the general conditions on the right side, a single row with general scalar query operator using
a single line operator: <>> = <= <>
column subquery: Usually a plurality of rows with the operator using
multi-line operator: in, any, some, all
# Scalar subquery
# Case: Who wages higher than the employee information ABEL
SELECT *
FROM employees
WHERE salary>(
SELECT salary
FROM employees
WHERE last_name='Abel'
);
Case #: job_id returned with the same number of 141 employees, salary of employees more than the employee's name No. 143, job_id and wages
SELECT
last_name,job_id,salary
FROM employees
WHERE job_id=(
SELECT job_id
FROM employees
WHERE employee_id=141
)
AND salary>(
SELECT salary
FROM employees
WHERE employee_id=143
);
Case #: return last_name minimum wage employees, job_id, and salary
SELECT last_name,job_id,salary
FROM employees
WHERE salary=(
SELECT MIN(salary)
FROM employees
);
Case #: Query No. 50 is greater than the minimum wage sector minimum wage and the minimum wage department id
SELECT department_id,MIN(salary)
FROM employees
GROUP BY department_id
HAVING MIN(salary)>(
SELECT MIN(salary)
FROM employees
WHERE department_id=50
);
# Unlawful use of standard quantum query
SELECT department_id,MIN(salary)
FROM employees
GROUP BY department_id
HAVING MIN(salary)>(
SELECT salary #单行操作符只能搭配标量子查询,而这是列子查询
FROM employees
WHERE department_id=50
);