database - How to use 'having' with 'where' in same select statement.Here, I want to display Total Guest<=10
问题描述
SQL written by me:
select distinct resortid,sum(adultcount+childcount)"TOTAL GUEST"
from booking
having count(1)>=1
group by resortid
order by resortid;
Output:
RESORTID TOTAL GUEST
---------- -----------
1001 11
1002 10
1003 2
1004 2
Expected Output:
RESORTID TOTAL GUEST
---------- -----------
1002 10
1003 2
1004 2
解决方案
删除不同的。改变having
做你想做的事。
select resortid,sum(adultcount+childcount)"TOTAL GUEST"
from booking
having sum(adultcount+childcount) BETWEEN 1 AND 10
group by resortid
order by resortid;
推荐阅读
- javascript - 使用 ADB 在 android WEBAPP 上启动
- intellij-idea - 草书IDE中的格式化程序
- cypress - 在 POST 之后捕获请求
- flutter - Flutter单元测试容器的边框半径
- python - 请求的多处理池使用情况
- windows - 使用 .bat 文件在路径中使用空格的 Window Powershell 打开文件夹
- python - 在某些行批量移动子集数据帧列
- bash - 为什么制作压缩存档(tar + pigz)会导致文件大大大于原始文件的总和?
- html - 如何让css不渲染div而不是让它不可见?
- javascript - 如何从另一个脚本导出新的 discord.js 客户端