gpt4 book ai didi

mysql - 查找 > 0 的最小值,也没有负值

转载 作者:行者123 更新时间:2023-11-29 15:48:47 26 4
gpt4 key购买 nike

我想从 MySQL 读取一行,它返回平均值、std dev pop 和最大值以及分钟。

基本上,我想从特定表中获取 MIN,但不是 0,或任何小于 0 的值。

我试过了

MIN(NULLIF(`stock_qty`, 0)) AS `stock_qty`,

作为 SELECT 参数,但仅当 MIN 为 0 时才返回 null

我当前的方法如下:

SELECT 
MAX(`stock_qty`) AS `stock_qty_max`,
MIN(`stock_qty`) AS `stock_qty_min`,
AVG(`stock_qty`) AS `stock_qty_avg`,
STDDEV_POP(`stock_qty`) AS `stock_qty_std`,
SUM(`stock_qty`) AS `stock_qty_sum`,
MAX(`adjusted_online_set`) AS `adjusted_online_set_max`,
MIN(`adjusted_online_set`) AS `adjusted_online_set_min`,
AVG(`adjusted_online_set`) AS `adjusted_online_set_avg`,
STDDEV_POP(`adjusted_online_set`) AS `adjusted_online_set_std`,
SUM(`adjusted_online_set`) AS `adjusted_online_set_sum`,
COUNT(*) AS `count`
FROM
`cat_product` AS `prod`
LEFT JOIN
`cat_position` AS `pos` ON pos.product_id = prod.product_id
RIGHT JOIN
`cat_product_website` AS `pweb` ON pos.product_id = pweb.product_id
WHERE
(pos.category_id = '8476')
AND ((prod.adjusted_online_set > 0) OR (prod.stock_qty > 0))

但这也会为两个字段返回负值。

最佳答案

分钟(案件 当stock_qty > 0 那么stock_qty 否则为空结尾) AS stock_qty

关于mysql - 查找 > 0 的最小值,也没有负值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56890312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com