aggregate function in mysql
Use HAVING:
SELECT dept.id, (invoices.col1 + invoices.col2 + invoices.col3) as sumTotal
FROM dept
INNER JOIN invoices ON invoices.id_dept = dept.id
HAVING sumTotal > 10000
The problem is that the WHERE clause is executed before the SELECT statement. And thus the sumTotal column is not yet available.
The HAVING clause is executed after the SELECT statement. It kinds of filter the resulst out after you have selected everything. Bare in mind though, because of that using HAVING is slower. It operates on the whole set of rows.
SELECT dept.id, (invoices.col1 + invoices.col2 + invoices.col3) as sumTotal
FROM dept
INNER JOIN invoices ON invoices.id_dept = dept.id
HAVING sumTotal > 10000
The problem is that the WHERE clause is executed before the SELECT statement. And thus the sumTotal column is not yet available.
The HAVING clause is executed after the SELECT statement. It kinds of filter the resulst out after you have selected everything. Bare in mind though, because of that using HAVING is slower. It operates on the whole set of rows.