开发者

making conditional inside mysql query

开发者 https://www.devze.com 2023-03-21 02:44 出处:网络
\'SELECT conversation_id, viewed_on,(\'max_unixtime().\' - las开发者_StackOverflow社区t_reply) AS newest_conversation FROM `Conversation_Participant` WHERE `user_id`=\'.$self->{user}->get(\'id\'
'SELECT conversation_id, viewed_on,('max_unixtime().' - las开发者_StackOverflow社区t_reply) AS newest_conversation FROM `Conversation_Participant` WHERE `user_id`='.$self->{user}->get('id').' ORDER BY newest_conversation DESC'

I need to set newest_conversation only when max_unixtime() - last_reply > last_viewed..

how can i set the if statement within my query?


Use a CASE statement.

...CASE WHEN max_unixtime() - last_reply > last_viewed 
        THEN ('max_unixtime().' - last_reply) 
        ELSE NULL END AS newest_conversation...
0

精彩评论

暂无评论...
验证码 换一张
取 消