大于在sql中的情况

时间:2014-05-26 23:06:07

标签: mysql sql

如何在SQL中使用大于'case'的情况?

我有以下工作正常,但等于100:

select case (TIMESTAMPDIFF(SECOND,last_active,now())) when 100 then 'True' else 'False' end from sessions where uuid=11 and token='test';

如何为(> 100)提供相同的查询?

如果您需要更多说明,请与我们联系!

由于

2 个答案:

答案 0 :(得分:2)

select case when (TIMESTAMPDIFF(SECOND,last_active,now())) > 100 then 'True' else 'False' end 
from sessions where uuid=11 and token='test';

答案 1 :(得分:0)

CASE有两种形式。

CASE expression WHEN Value THEN Value [ WHEN Value THEN Value ] ELSE Value END

CASE WHEN Expression THEN Value [ WHEN Expression THEN Value ] ELSE Value END

你想要后者。

SELECT case WHEN (TIMESTAMPDIFF(SECOND,last_active,now())) > 100 then 'True' else 'False' end 
FROM sessions where uuid=11 and token='test';