MySql高级查询

发布 2021-05-08 19:22:28 阅读 3428

高级查询。

1.连接查询(对列的扩展)

第一种形式。

select * from info,nation #会形成笛卡尔积。

select * from info,nation where = #加入筛选条件。

select from info,nation where =

#查询指定列。

select as '代号', as '姓名',sex as '性别', as '民族',birthday as '生日' from info,nation where =

#换表头。第二种形式:

select * from info join nation #join连接,形成笛卡尔积查询很慢。

select * from info join nation on = #join关键字。

2.联合查询(对行的扩展)

select * from info where nation = n002'

union #关键字。

select * from info where code = p002'

3.子查询(无关子查询) 如果子查询语句可以单独拿出来执行,就是无关查询。

在一个sql语句中有两个子查询,其中一个a查询的结果作为另一个b的。

select查询条件,a成为里层查询,b为外层查询或父查询。

查询民族为'汉族'的人员信息:

select * from info where nation = select code from nation where name = 汉族')

查询民族为 '汉族' 或者 '回族' 的人员信息。

select * from info where nation in (select code from nation where name = 汉族' or name = 回族')

select * from info where nation not in (select code from nation where name = 汉族' or name = 回族')

#in 关键字 not in不在表里。

4.子查询(相关子查询)

查询同一系列的油耗要比平均油耗低的汽车信息。

子查询。select **g(oil) from car where brand =

父查询。select * from car where oil《平均油耗。

select * from car a where < select **g( from car b where =

# 是查询条件, 是逐条的信息。

MySQL数据库高级查询和多表查询 二

机试测试试卷。mysql数据库应用与开发 注意 考试结束试卷必须交回,不交回试卷者成绩无效。题目 mysql 数据库高级查询和多表查询。一 语言和环境 a 实现技术 sql 语句练习 b 环境要求 mysql5.7 n icat 二 实验要求。1 创建名为 s t 的数据库,参数全部使用 utf 8...

MySQL高级教程笔记

mysql 高级。1 标题1 错误!未定义书签。1.1 标题2 错误!未定义书签。1.1.1 标题3 错误!未定义书签。mysql中的sql编程的话题。触发器,存储函数,存储过程。以上的是三个名词,在sql编程中,地位是 程序的载体,程序的结果。编程所涉及的要素 变量,数据类型,流程控制,函数,运算...

ORACLE高级查询

本章目标 多表查询。联接查询 inner join 内联接 left outer join 左外联接 right outer join 右外联接 full join 全联接 子查询。集合操作。union 联合 union all 联合所有 intersect 交集 minus 减集 一 连接类型。o...