You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 BY clause 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 by user_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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:58:05