gpt4 book ai didi

mysql - 选择最大字段值或零值

转载 作者:行者123 更新时间:2023-11-29 01:13:19 25 4
gpt4 key购买 nike


我有表 user_groups 并且我需要选择字段 time 的最大 int 值或 0 如果有 user_group 实体在 time 字段中有 0
像这样:

SELECT time FROM user_groups
WHERE
IF (time == 0) THEN time = 0
ELSE MAX(time)

我需要多平台解决方案。

更新:

我正在使用 mysql
在这种情况下:

id | time |
1 | 5 |
2 | 6 |

我期待 6
在这种情况下:

id | time |
3 | 5 |
4 | 6 |
5 | 0 |

我期待 0

最佳答案

用例如何

SELECT case when min(time) = 0 then 0 else max(time) end FROM user_groups;

或者如果时间可以 < 0 但只应考虑时间 0 或更多,那么添加 where 子句会有所帮助

SELECT case when min(time) = 0 then 0 else max(time) end FROM user_groups where time >= 0;

关于mysql - 选择最大字段值或零值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26751882/

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