目录
数量 count(*或者0)
select count()from表名
select count(*)from表名
求数量
select count(字段名)from表名
求和
select sum(*)from表名
求平均值
select avg(字段名)from 表名
最小值
select min(字段名)from 表名
最大值
select max(字段名)from 表名
分组查询
select 字段名, sum(sal), avg(comm), count(comm)from表名 group by 字段名;
select字段名, sum(sal).... from表名 group by 字段名 having 条件;
为字段取别名(as可以省略)
select 字段名 (可写函数)as 字段别名
查询daniel老师的上课教室
交叉连接4*3=12条
select * from 表名1 cross join 表名2
内连接
select * from 表名1 inner join 表名2 on 表名1.表1字段名 = 表名2.表2字段名;
左连接
select * from 表名1 left join 表名2 on 表名1.表1字段名 = 表名2.表2字段名;
右连接
select * from 表名1 right join 表名2 on 表名1.表1字段名 = 表名2.表2字段名;
查询Daniel老师的授课表课程名
子查询in
select * from 表名 where 条件 字段 in (查询语句);
子查询not in
select * from 表名 where 条件 字段 not in (查询语句);
子查询exists
select * from 表名 where exists (查询语句);
子查询any
select * from 表名 where 条件 字段 > any (查询语句);
子查询all
select * from 表名 where 条件 字段 > all(查询语句);