简体   繁体   English

大于在sql中的情况

[英]greater than in case when in sql

How can I use greater than in 'case when' in SQL? 在SQL中,如何使用大于'case when'的值?

I have the following which works fine, but for equal to 100: 我有以下工作正常,但等于100:

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

How can I have the same query for (>100)? 如何对(> 100)进行相同的查询?

Please let me know if you need more clarification! 如果需要更多说明,请告诉我!

Thanks 谢谢

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

CASE has two forms. CASE有两种形式。

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

and

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

You want the latter. 您想要后者。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM