„Operatorwert in Where-Bedingung' ins Chinesische übersetzen als „Operatorwert in Where-Bedingung'
P粉754477325
P粉754477325 2023-09-13 13:58:40
0
1
669

Wie mache ich das?

SELECT sum(buy-sale) as istock form tbl_product
where istock > 0

Die folgenden Methoden interessieren mich nicht.

SELECT sum(buy-sale) as istock form tbl_product
where sum(buy-sale)> 0

P粉754477325
P粉754477325

Antworte allen(1)
P粉621033928

你只需要将WHERE替换为HAVING ;-)

SELECT SUM(`buy-sale`) AS `istock` FROM tbl_product HAVING `istock` > 0

但是这将返回所有记录的总和。通常你在按照某个条件进行分组时才会这样做,比如按产品ID或其他条件。例如:

-- 查找大订单
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;

这可能会有所帮助:https://www.mysqltutorial.org/mysql-having.aspx

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage