How can I use greater than in 'case when' in SQL?
I have the following which works fine, but for equal to 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)?
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 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';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.