suchen

Heim  >  Fragen und Antworten  >  Hauptteil

„Operatorwert in Where-Bedingung“ ins Chinesische übersetzen als „Operatorwert in Where-Bedingung“

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粉754477325P粉754477325444 Tage vor670

Antworte allen(1)Ich werde antworten

  • P粉621033928

    P粉6210339282023-09-14 11:34:43

    你只需要将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

    Antwort
    0
  • StornierenAntwort