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

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

 

1.链接查询

适用于有外键关系的  没有任何关系没法用这个连

Select  *  from  info,nation                                 同时查询这俩表并把两表每个数据相互组合,形成笛卡尔积

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

select  Info.code,Info.name,Info.sex,Nation.name as '民族',Info.birthday   from Info,Nation where Info.nation=Nation.code

关键字链接

Select  * from  info  join  nation  on  info.Nation=   nation.code                                  join  on  关键字

 

 

2.联合查询   列要一致

Select   code,name   from  info

union

Select   code,name   from  nation

3.子查询

子查询查询的结果作为父查询的条件

(1)无关子查询

       查民族为’汉族’的所有学生信息

Select  *  from  info  where  nation=                                        父查询

(

Select  code  from  nation  where name = ‘汉族’                           子查询

)                                                                                                        

 

查询生产厂商为一汽大众的所有汽车信息

Select  *  from  car   where  brand=()

Select brand_code from  brand  where   prod_code=()

Select  prod_code  from  productor  where prod_name=’一汽大众’

 

合并变成  ↓

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

 

很确定的信息用‘=’ 不确定的用‘in’

 

(2)相关子查询

子查询在执行时候需要用到父查询的内容

 

查询汽车表中,汽车油耗小于该系列平均油耗的所有信息

Select * from  car  where  oil<(该系列平均油耗)

Select avg(oil)  from  car  where  brand =  (该系列)

组合 变成↓

Select * from  car a  where  oil<( Select avg(oil)  form  car b  where  b.brand  =  a.brand)

a.brand 就是当前卡主的那条信息

 

转载于:https://www.cnblogs.com/sq45711478/p/5969904.html

你可能感兴趣的文章
CentOS下安装JDK1.7
查看>>
LDAP DIT设计参考
查看>>
iptables详解
查看>>
Protostuff 介绍
查看>>
一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别...
查看>>
参数验证其实可以更简明一点
查看>>
Set up Mule runtime env with mule-standalone-3.6.0
查看>>
Linux基础-linux命令:csplit
查看>>
core_framework —— 基于libev的轻量级lua网络开发框架
查看>>
回到顶部
查看>>
DES/3DES(TripleDES)加密、解密测试数据
查看>>
Maven项目标准目录结构
查看>>
Tomcat 系统架构与设计模式,第 1 部分: 工作原理
查看>>
Hadoop输出参数信息详解(16)
查看>>
ERROR 2002 (HY000): Can't connect to local MySQL错误
查看>>
Java版冒泡排序法
查看>>
关于FB4.6插件安装后默认语言环境的更改问题
查看>>
免费分区助手
查看>>
Javascript通过Name调用Function
查看>>
统计当前在线用户数量
查看>>