Error with having clause

Viewed 29344
select SUM (Bill) from ProductSaleReport group by PCI 
having MONTH(Date) between 1 and 3

Could any one please help me finding the issue.?

I am getting the errors:

Msg 8121, Level 16, State 1, Line 1
Column 'ProductSaleReport.Date' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8121, Level 16, State 1, Line 1
Column 'ProductSaleReport.Date' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.

4 Answers

Try this,

select SUM (Bill) from ProductSaleReport group by PCI having MIN(MONTH(Date))>=1 and MAX(MONTH(Date))<=3

Related