> 文档中心 > DQL数据库查询语言

DQL数据库查询语言


函数

avg()

min()

max()

count()

sum()

组函数必须结合 group by 使用

sum(if(条件,1,0))/count(*) 当条件满足则为1否则为0

group by 可以分多组 例: group by column1,column2

结合having 可以设置查询条件

select * from 表名 where 条件1 group by column1 having count(*) >1

子查询

将一个表的查询结果作为新的表来进行查询

select * from (select column1 from 表1) as c where 条件

多表查询

内连接

join on

例:

select *

from table1 join table2

on table1.no=table2.no

外连接

左外链接

left join on

以左边的表为主表

select e1.ename , e2.ename
from emp e1 left join emp e2on e1.mgr=e2 . empno;

右外连接

right join on

以右边的表为主表

select e1.ename , e2.ename
from emp e1 rightjoin emp e2on e1.mgr=e2 . empno;

92语法

select *

from table1,table2

where table1.no=table2.no

in

条件判断使用,类似于集合

between and

表示范围

between 1 and 5

表示1到5之间