首页 > 解决方案 > 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

标签: databaseoracle

解决方案


删除不同的。改变having做你想做的事。

 select resortid,sum(adultcount+childcount)"TOTAL GUEST" 
 from booking 
 having sum(adultcount+childcount) BETWEEN 1 AND 10   
 group by resortid
 order by resortid;

推荐阅读