Orale第6课.docVIP

  • 1
  • 0
  • 约1.17万字
  • 约 4页
  • 2017-06-13 发布于河南
  • 举报
Orale第6课

第六章 分组函数 一组函数 1. AVG 平均值 语法:select avg(列名) from 表名; select avg(sage) from student; 题1:求员工的平均工资 SQL select avg(salary) from employees; 2. COUNT 计数 语法1:select count(列名) from 表名; select count(sage) from student; 语法2:select count(*) from 表名; select count(*) from student; 注意:语法1中如果被指定的列名,当中有null只是,不做统计。 题1:SQL select count(COMMISSION_PCT) from employees; 题2:SQLselect count(nvl(COMMISSION_PCT,0)) from employees 3. MAX 最大值 语法1:select max(列名) from 表名; select max(sage) from student; 4. MIN 最小值 语法1:select min(列名) from 表名; select min(sage) from student; 5. SUM 合计 语法1:select sum(列名) from 表名; select sum(sage) from student; 6. TDDEV 标准差 7. VARIANCE 方差 二group by 错误代码:select sdept,avg(sage) from student 注意:当查询时出现分组函数时,如果出现普通的列,必须用group by进行分组。 语法:select 列名1,列名2,分组函数1,分组函数2 from 表名 Group by(列名1,列名2) 例:select sdept,avg(sage) from student group by sdept 题1:求员工表中,部门的平均工资 select department_id,avg(salary) from employees group by department_id; 三 having 语法:select 列名 from 表名1,表名2 where 表名1.列名=表名2.列名2 Group by 列名 having 条件; 例:select c.cname,count(c.cname) from sc s,course c where s.cno=c.cno group by c.cname having count(c.cname)=3 注意:如果对组函数进行判断时,必须用having。 题1:查询部门中人数大于等于5人的部门名称。 select dept.department_name from employees emp,departments dept where emp.department_id=dept.department_id group by dept.department_name having count(*)=5; 题2:查询部门平均工资大于等于10000的部门名称 select dept.department_name from employees emp,departments dept where emp.department_id=dept.department_id group by dept.department_name having avg(emp.salary)=10000; 四:select语句 SELECT column, group_function FROM table [WHERE condition] [GROUP BY group_by_expression] [HAVING group_condition] [ORDER BY column];

文档评论(0)

1亿VIP精品文档

相关文档