标签:
组函数针对的是指定字段的非空值。注意:where子句中不能出现组函数!!!
id name dept_id salary manager_id
0001 wangda 101 8500[NULL]
0002 wanger 1033 000 0009
0003 wangsan 102 4000 0006
0004 wangsi 104 2000 0005
0005 wangwu 104 6000 0001
0006 wangliu 102 7000 0001
0007 wangqi 105 5000 0008
0008 wangba 105 5500 0001
0009 wangjiu 103 6000 0001
0010 wangshi 104 900 0005
0011 wangsy 103 5000 0009
0012 wangse [NULL]3000[NULL]
SELECT
dept_id,
avg(salary)
FROM
person
GROUP BY
dept_id
;dept_id avg(salary)
[NULL] 3000.000000
101 8500.000000
102 5500.000000
103 4666.666667
104 2966.666667
105 5250.000000
SELECT
p.dept_id,
dept_name,
avg(salary)
FROM
person p,dept d
where p.dept_id = d.dept_id
GROUP BY
p.dept_id
HAVING
avg(salary)>5000;
dept_id dept_name avg(salary)
101 zongwu 8500.000000
102 zhenggong 5500.000000
105 renshi 5250.000000
标签:
原文地址:http://www.cnblogs.com/rainyeagle/p/4599461.html