mysql - The Having statement does not work in my sql
问题描述
Try to write a query like this:
select distinct S.course_id,count(S.course_id)
from Section As S
Where Exists (Select S.course_id
From Section
Where S.year='2019'
Having count(S.course_id)>1 )
Group by S.course_id
Order by S.course_id DESC;
But the result countinue to give me course_ids that does not appear more than once.
course_id | count(S.course_id) |
---|---|
PHY-101 | 1 |
EE-181 | 1 |
CMPE-347 | 1 |
CMPE-190 | 2 |
CMPE-101 | 1 |
BIO-101 | 1 |
解决方案
尝试修改您的查询如下
select s.course_id, count(s.course_id)
from Section as s
Where Exists (Select * From Section s2
Where s2.year='2019' and s2.course_id=s.course_id
group by s2.course_id
Having count(*)>1)
Group by s.course_id
Order by s.course_id DESC;
推荐阅读
- javascript - 如何修复我的 JS 老虎机 - 复选框错误
- api - Microsoft 合作伙伴 API 网络配置文件没有 MPN id
- javascript - 如何在填写字段时动态添加 HREF?
- java - 如何在 Spring Boot Eureka Config 中提供外部 .yml 文件?
- laravel - 如何从 laravel 中的多维数组发送特定数据
- flutter - Flutter Youtube 风格图片黑色叠加
- java - 在 Java 中,哪种阶乘函数的实现通常更快?
- mysql - 语句不完整mysql存储过程
- python - 使用 libpcap 进行 TLS 解密
- python-3.x - 如果存在重复行,则总结 Pandas DataFrame 中的一列