Aggregate function on where clause

Hi,

I know that aggregate function in where clause is not allowed but is there any alternative for this query

SELECT
SUM(inv.total_bill) AS total_bill,
MIN(store.code) AS code,
from mybucket inv
WHERE  inv.type = 'invoice' AND  SUM(inv.total_bill)  > 500 ORDER BY total_bill DESC LIMIT 10

Use having or filter out in parent query

SELECT
SUM(inv.total_bill) AS total_bill,
MIN(store.code) AS code,
from mybucket inv
WHERE  inv.type = 'invoice'
HAVING  SUM(inv.total_bill)  > 500 
ORDER BY total_bill DESC 
LIMIT 10
1 Like