I have a table with order id, product id and the quantity of each product of that order (like in the table below). And I have to select the order_id and it's total quantity where the quantity is more than 5.
+----------+------------+----------+
| order_id | product_id | quantity |
+----------+------------+----------+
| 1 | 1 | 6 |
| 1 | 2 | 1 |
| 2 | 3 | 3 |
| 2 | 2 | 2 |
| 3 | 1 | 3 |
| 3 | 3 | 5 |
+----------+------------+----------+
What I've tried is
SELECT order_id, SUM(quantity) AS qty
FROM order_product
WHERE qty > 5 /* <-- Cannot use qty here */
GROUP BY order_id;
ERROR 1054 (42S22): Unknown column 'qty' in 'where clause'
AFAIK the where clause executed before summing the quantity columns so I cannot use qty there but is there any way to run the condition after the aggregation or is there any other way to solve it?