关于查询
来源:互联网 发布:java项目开发视频 编辑:程序博客网 时间:2024/05/16 19:00
【1】内联查询
select p.pname, c1_sum1 , c2_sum2
from p ,
(select id, sum(q1 ) c1_sum1 from s1 group by id) s1,
(select id, sum(q2 ) c2_sum2 from s2 group by id) s2
where p.id = s1.id
and p.id = s2.id
这种类型查询的特点是,在from 与where 之间有新的select 查询,这种查询在执行过程中的结果被存在了临时的视图中所以,也称为内联试图查询。
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【2】标量子查询
select p.pname,
(select sum(q1) c1_sum1 from s1 where s1.id = p.id) c1_sum1,
(select sum(q2) c1_sum1 from s2 where s2.id = p.id) c2_sum2
from p
这种类型查询的特点是在select 与from 之间有新的select 查询。
Single-row subqueries return zero rows or one row to the outer SQL statement. There is a special case of a single-row subquery that contains exactly one column; this type of subquery is called a scalar subquery .
select 后面的查询,是典型的标量查询
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【3】嵌套子查询
select column1, column2 , column3
from Table1
where column1 IN (select column1 from Table2)
在where 的语句之后的子查询被称为嵌套子查询。
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【4】关联子查询
SELECT o1.CustomerID, o1.OrderID , o1.OrderDate
FROM Orders o1
WHERE o1.OrderDate = ( SELECT Max (OrderDate )
FROM Orders o2
WHERE o2.CustomerID = o1.CustomerID)
外部查询与内部查询有连接条件的where 后查询被称为关联子查询。
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【5】 with子查询分解
with
c1_vw as (select id,sum (q1 ) sum1 from s1 group by id),
c2_vw as (select id,sum (q2 ) sum2 from s2 group by id),
c1_c2 as (select t1.id,t1.sum1,t2.sum2 from c1_vw t1,c2_vw t2 where t1.id =t2.id)
select p.pname,sum1 ,sum2
from p ,c1_c2
where p.id =c1_c2.id
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
select p.pname, c1_sum1 , c2_sum2
from p ,
(select id, sum(q1 ) c1_sum1 from s1 group by id) s1,
(select id, sum(q2 ) c2_sum2 from s2 group by id) s2
where p.id = s1.id
and p.id = s2.id
这种类型查询的特点是,在from 与where 之间有新的select 查询,这种查询在执行过程中的结果被存在了临时的视图中所以,也称为内联试图查询。
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【2】标量子查询
select p.pname,
(select sum(q1) c1_sum1 from s1 where s1.id = p.id) c1_sum1,
(select sum(q2) c1_sum1 from s2 where s2.id = p.id) c2_sum2
from p
这种类型查询的特点是在select 与from 之间有新的select 查询。
Single-row subqueries return zero rows or one row to the outer SQL statement. There is a special case of a single-row subquery that contains exactly one column; this type of subquery is called a scalar subquery .
select 后面的查询,是典型的标量查询
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【3】嵌套子查询
select column1, column2 , column3
from Table1
where column1 IN (select column1 from Table2)
在where 的语句之后的子查询被称为嵌套子查询。
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【4】关联子查询
SELECT o1.CustomerID, o1.OrderID , o1.OrderDate
FROM Orders o1
WHERE o1.OrderDate = ( SELECT Max (OrderDate )
FROM Orders o2
WHERE o2.CustomerID = o1.CustomerID)
外部查询与内部查询有连接条件的where 后查询被称为关联子查询。
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯┯
【5】 with子查询分解
with
c1_vw as (select id,sum (q1 ) sum1 from s1 group by id),
c2_vw as (select id,sum (q2 ) sum2 from s2 group by id),
c1_c2 as (select t1.id,t1.sum1,t2.sum2 from c1_vw t1,c2_vw t2 where t1.id =t2.id)
select p.pname,sum1 ,sum2
from p ,c1_c2
where p.id =c1_c2.id
┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷┷
0 0
- 关于查询
- 关于sql联合查询
- 关于 nutch 查询(收藏)
- 转 关于查询语句
- 关于按日期查询
- 关于ACCESS模糊查询
- 关于SQL分段查询
- 关于MYSQL 查询缓存
- 关于查询顺序
- 关于日期的查询
- 关于查询和 翻页
- 关于数据查询
- 关于模糊查询--find
- 关于级联查询
- 关于查询与过滤
- sql关于时间查询
- 关于SQL分区查询
- 关于时间查询
- JavaScript的那些书
- 内存管理
- 华为机试 - 字符串去重复字节/字符串去连续重复字节
- linux下libxml2库使用说明
- 为mysql 增加远程访问权限
- 关于查询
- 并查集 How Many Answers Are Wrong HDU 3038
- javascript推荐书籍
- FatMouse and Cheese
- mysql时间函数
- batch 截取字符串
- Linux Yum安装配置与安装命令应用
- POJ 1269 Intersecting Lines(判断直线相交)
- Fedora yum光盘安装及运行命令