1.distinct//去重
select distinct 字段A from table
2.where//条件筛选
select * from table where 条件(字段 运算符 值)
3.and、or//并运算与或运算
4.having//用于分组后的条件过滤
SELECT cno, COUNT(*) nums FROM tbl_student_class GROUP BY cno HAVING cname = '影视9班';
1.AVG()
//返回平均值
select AVG(字段A) from table
2.ceil()
//向上取整
select ceil(25.13621) from dual
返回26
3.floor()
//向下取整
select floor(2.547) from dual
返回2
4.count()
//分条件计数
select count(*) from table
//返回表里的数据条数(即行)
select count(字段x) from table
//返回该字段的数据条数,NULL不计数
select count(*)where 条件
//返回该条件下的数据条数
SELECT COUNT(DISTINCT 字段A) FROM table
5.聚合函数:AVG()、sum()、max()、min()、count()
//在计算时,列作为参数的话自动排除NULL
select avg(字段) from table
//返回平均数
select max(字段) from table
//返回最大值
select sum(字段) from table
//返回总和
6.decode(字段,字段值1,返回值1,字段值2,返回值2,以上条件都不符合的返回值)
//相当于if else语句
SELECT 字段A,字段B,DECODE(字段C,值1,返回值1,值2,返回值2,都不符合的返回值3) FROM table
//if C=值1
返回值1;
else if C=值2
返回值2;
else 返回值3;
7.first()
//不太懂,大概是返回第一条数据吧?
SELECT w.dept, MAX(w.salaries) KEEP(DENSE_RANK FIRST ORDER BY w.age) max_salary FROM workers w WHERE 1=1 GROUP BY dept;
//返回年龄最小的人中的最高工资
用了分析函数KEEP (DENSE_RANK FIRST/LAST)