博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据库高级查询
阅读量:4696 次
发布时间:2019-06-09

本文共 1010 字,大约阅读时间需要 3 分钟。

1.联合查询(用的不多)

select code,name from info

union

select code,name from nation

对行的扩展

 

select code,name from nation

2.连接查询

select * from info,nation 会形成大量数据,笛卡尔积

select  * from info,nation where info.nation=nation.code

select info.code,info.name,info.sex,nation.name,info.birthday from info,nation where info.nation=nation.code

 

select info.code,info.name,info.sex,nation.name,info.birthday from info join nation  on info.nation=nation.code

left join 左连接

 

3.子查询(重要)

外层查询,里层查询,子查询的结果作为父查询的条件使用

无关子查询

  子查询和父查询没有关系,子查询单独拿出来可以执行

1.查询民族为“汉族”的所有人员信息

select * from info where nation=(

select code from nation where name=‘汉族’)

2.查询所有厂商是“一汽大众”的汽车信息

selec * from car where brand in((select brand_code from brand where prod_code in(select prod_code from Productor where prod_name='一汽大众'))

相关子查询

查询油耗低于该系列平均油耗的汽车信息
select * from car where oil<(该系列平均油耗)
select avg(oil) from car where brand='该系列'
select * from car a where oil<(select avg(oil) from car b where b.brand=a.brand)

转载于:https://www.cnblogs.com/niushuangmeng/p/8169101.html

你可能感兴趣的文章
Java 内存模型详解
查看>>
并发之初章Java内存模型
查看>>
ThreadLocal可以解决并发问题吗?
查看>>
1011 Sticks
查看>>
poj 3373 Changing Digits
查看>>
CROC-MBTU 2012, Elimination Round (ACM-ICPC) E. Mishap in Club
查看>>
爬虫抓取表格中的数据
查看>>
redis-3.0.0_rc5的RPM包制定
查看>>
JQuery Ajax 全解析
查看>>
Jfinal集成Spring
查看>>
JQuery操作class
查看>>
【easy】101. Symmetric Tree
查看>>
Android 4.0 NDK Updated
查看>>
第六次评分
查看>>
SAP FI配置步骤
查看>>
BZOJ 2288: 【POJ Challenge】生日礼物 优先队列+贪心+链表
查看>>
Basic Level 1006. 换个格式输出整数 (15)
查看>>
VC++6.0安装步骤
查看>>
josephus问题
查看>>
jedate-开始使用一款好用的时间插件
查看>>