MySQL查询排序优化:user_id降序,同user_id按申请日期降序
Adjusted MySQL Query for Multi-Level Sorting
Got it! To get the sorting behavior you want—first sorting by user_id in descending order, and then sorting by user_job_application_date in descending order whenever user_id values are the same—you just need to add the second sorting condition to your ORDER BY clause.
Here's the modified query:
SELECT * FROM `user_job_application` ORDER BY `user_job_application`.`user_id` DESC, `user_job_application`.`user_job_application_date` DESC;
Quick breakdown of how this works:
- The
ORDER BYclause evaluates sorting rules from left to right. - First, all rows are sorted in descending order based on
user_id. - For any group of rows that have the same
user_id, those rows will then be sorted in descending order byuser_job_application_date—so the most recent job applications for the same user will show up first within their user group.
内容的提问来源于stack exchange,提问作者Shubham Mishra
相关产品推荐
相关产品推荐

