Error with having clause

后端 未结 3 1174
抹茶落季
抹茶落季 2021-01-17 20:08
select SUM (Bill) from ProductSaleReport group by PCI 
having MONTH(Date) between 1 and 3

Could any one please help me finding the issue.?

<
3条回答
  •  孤城傲影
    2021-01-17 20:51

    Use WHERE to filter before group by

    HAVING is used to filter data after the group by occurs

    select SUM (Bill) -- comment: you need to add the PCI column since you use it in the group by right?
    from ProductSaleReport 
    WHERE MONTH(Date) between 1 and 3
    group by PCI 
    

提交回复
热议问题