我想选择所有最小可用数量等于零的产品名称


I want to select all those products name whose minimum available quantity is equal to zero

我有两个数据库表nrk_productnrk_stock

我想从nrk_product表中选择所有最小可用数量等于零的产品名称。

我正在写下面的查询,它显示了那些可用数量大于零的记录,但我想要相反的结果。

SELECT * FROM `nrk_product` AS `np`     
    LEFT JOIN `nrk_stock`  AS `ns`  
    ON `np`.`id` = `ns`.`product_id`        
    GROUP BY `np`.`id`
    HAVING (SUM(`ns`.`credit_quantity`) - SUM(`ns`.`debit_quantity`)) > 0 

如果你只想相反,而不是用小于等于(<=)的替换大于(>)

SELECT * FROM `nrk_product` AS `np`     
    LEFT JOIN `nrk_stock`  AS `ns`  
    ON `np`.`id` = `ns`.`product_id`        
    GROUP BY `np`.`id`
    HAVING (SUM(`ns`.`credit_quantity`) - SUM(`ns`.`debit_quantity`)) <= 0

你能试试这个吗:-

=0< 0

SELECT nrk_product FROM nrk_product AS np
LEFT JOIN nrk_stock AS ns
ON np.id = ns.product_id
GROUP BY np.id HAVING (SUM(ns.credit_quantity) - SUM(ns.debit_quantity)) = 0
SELECT * FROM `nrk_product` AS `np`     
    LEFT JOIN `nrk_stock`  AS `ns`  
    ON `np`.`id` = `ns`.`product_id`        
    GROUP BY `np`.`id`
    HAVING (SUM(`ns`.`credit_quantity`) - SUM(`ns`.`debit_quantity`)) < 1