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

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 04:42:35
oracle中HAVINGcount(1)groupbysexhavingcount(*)>4;怎么使用?oracle中HAVINGcount(1)groupbysexhavingcount(*)>4

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

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之类的聚合函数也同样