SELECT SUM(`buy-sale`) AS `istock` FROM tbl_product HAVING `istock` > 0
But this will return the sum of all records. Usually you would do this when grouping by some criteria, such as by product ID or other criteria. For example:
-- 查找大订单
SELECT
`order_number`,
SUM(`quantity_ordered`) AS `quantity_sum`,
SUM(`product_price` * `quantity_ordered`) AS `total`
FROM
order_details
GROUP BY
`order_number`
HAVING
`total` > 1000;
You just need to replace
WHEREwithHAVING;-)But this will return the sum of all records. Usually you would do this when grouping by some criteria, such as by product ID or other criteria. For example:
-- 查找大订单 SELECT `order_number`, SUM(`quantity_ordered`) AS `quantity_sum`, SUM(`product_price` * `quantity_ordered`) AS `total` FROM order_details GROUP BY `order_number` HAVING `total` > 1000;This might help: https://www.mysqltutorial.org/mysql-having.aspx