mysql 分級構建排序語句

1.使用case when  


ORDER BY CASE WHEN end_time>NOW() AND start_time < NOW() THEN 0 WHEN start_time > NOW() THEN 1 ELSE 2 END,ABS(TIMESTAMPDIFF(second,start_time,NOW()))

2.使用 if


ORDER BY IF(end_time>NOW(),0,1),ABS(TIMESTAMPDIFF(SECOND,start_time,NOW()))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章