Mysql: order a table using 2 columns in Descending order

泪湿孤枕 提交于 2019-12-12 06:34:36

问题


i'm a bit stomped..

I'm trying to achieve a fairly simple logic..

I have a "user_sessions" table with log_in and log_out (int, epoch time stamps)

   userID | log_in | log_out

trying to show the RECENT activities, I need to list all the sessions in DESCENDING ORDER based on the LATEST ACTIVITY, and this could either be log_in or log_out.. and this is where i'm stomped. I tried different ORDER and SORT methods... I'm just not getting it.


回答1:


SELECT *
FROM user_sessions
ORDER BY GREATEST(log_in, log_out) DESC


来源:https://stackoverflow.com/questions/21618224/mysql-order-a-table-using-2-columns-in-descending-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!