作业帮 > 综合 > 作业

oracle中 HAVING count(1) group by sex having count(*)>4; 怎么使用

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/02 00:59:59
oracle中 HAVING count(1) group by sex having count(*)>4; 怎么使用?
譬如如下数据
id value
1 2
1 3
2 3
3 5
3 6
可以写个语句统计value的分组
select id,sum(value) from table group by id having sum(value)>=5
这样的结果就是
1 5
3 11
其实这句的意思就是
select id,sum(value) from table where sum(value)>=5 group by id
但是oracle中,计算字段没法当作条件来用,所以就用having 来表示
你的例子是count(*)也是一个道理的,当然什么avg,max,min之类的聚合函数也同样