gpt4 book ai didi

sql - 根据 SQL 中耗时返回 true/false

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

假设我们有一个如下所示的 SQL 查询

select now()-insert_time AS time_elapsed, *
from account
where enabled = true AND machine = 'one'
limit 1

是否可以为 now()-insert_time AS time_elapsed 返回一个 bool 列?如果超过 4 小时,我希望它为真,如果少于 4 小时,则为假。

最佳答案

您可以直接在查询中比较它

 select now()-insert_time AS time_elapsed,
now()-insert_time >= '4 hours' as status,
*
from account
where enabled = true

一般情况下,放在CASE表达式中,其他值输出

 select now()-insert_time AS time_elapsed,
CASE
WHEN now()-insert_time >= '4 hours' THEN 'Greater than 4 hours'
ELSE 'Less than 4 hours'
END as status,
*
from account
where enabled = true
AND machine = 'one'
limit 1

希望对您有所帮助。

关于sql - 根据 SQL 中耗时返回 true/false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50147987/

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