我可以使用带有 having 子句的字符串类型吗(比如 ....having sex='male')
Can i use string type with having clause(Like ....having sex='male')
select country,count() from employee group by country having id<4;
这个查询工作正常但是当我使用
select country,count() from employee group by country having sex='male';
显示错误:-ORA-00979:不是 GROUP BY 表达式
为什么??
第一个应该可行,因为国家和 ID 之间有相同的聚合级别(每个国家只有一个 ID)
第二个不起作用,因为性别不是聚合列并且聚合级别不同,所以
如果聚合子句中不需要 sex,则应使用 where 进行过滤
select country,count(*) from employee
where sex='male'
group by country;
或者您可以将性别添加到分组依据并过滤
select country,sex, count(*) from employee
group by country, sex
having sez='male';
select country,count() from employee group by country having id<4; 这个查询工作正常但是当我使用 select country,count() from employee group by country having sex='male'; 显示错误:-ORA-00979:不是 GROUP BY 表达式 为什么??
第一个应该可行,因为国家和 ID 之间有相同的聚合级别(每个国家只有一个 ID)
第二个不起作用,因为性别不是聚合列并且聚合级别不同,所以
如果聚合子句中不需要 sex,则应使用 where 进行过滤
select country,count(*) from employee
where sex='male'
group by country;
或者您可以将性别添加到分组依据并过滤
select country,sex, count(*) from employee
group by country, sex
having sez='male';