首页 > 数据库技术 > 详细

Oracle_071_lesson_p8

时间:2018-08-01 11:33:45      阅读:200      评论:0      收藏:0      [点我收藏+]
嵌套子查询subquery

单行子查询
select select_list
from table
where expr operator
(select select_list from table);
operator includes a comparison condition such as >, =, or IN

如:
select last_name,hire_date
from employees
where hire_date > (select hire_date from employees where last_name = ‘Davies‘);
[可选] and ID=(select .......);

如:
select A from table
group by C
having min(column)>(select ......);
当子查询有group by 时,其输出行数只能是1行;

多行子查询
IN , ANY , ALL
select employee_id,last_name,job_id,salary
from employees
where salary<ANY
(select salary from employees where job_id=‘IT_PROG‘)
and job_id <> ‘IT_PROG‘;
说明:
<ANY means less than the maximum. >ANY means more than the minimum. =ANY is equivalent to IN.

多列子查询
Syntax:
SELECT column, column, ...
FROM table
WHERE (column, column, ...) IN
(SELECT column, column, ...
FROM table
WHERE condition);
如:
select first_name,dapartment_id,salary
from employees
where (salary,department_id) IN
(select min(salary),department_id
from employees
group by department_id)
order by department_id;

空值子查询
子查询语句要把NULL处理掉才有结果
SELECT last_name FROM employees
WHERE employee_id NOT IN
(SELECT manager_id
FROM employees
WHERE manager_id IS NOT NULL);

Oracle_071_lesson_p8

原文:http://blog.51cto.com/3938853/2153031

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!