按日期排序记录,然后按项目ID排序

时间:2022-05-10 01:21:25

I want to sort the result first by date and then by id.

我想先按日期排序结果,然后按id排序。

I used the query

我用过这个查询

SELECT payment_date,project_id FROM `payments` ORDER BY payment_date desc, project_id desc 

But it did not work. I want first sort the data by date and get the project id who have max date after that records below first row show all the date based on particular project id.

但它没有用。我想首先按日期对数据进行排序,并获得具有最大日期的项目ID,在第一行之后的记录显示基于特定项目ID的所有日期。

like

喜欢

按日期排序记录,然后按项目ID排序

Please help me to get the result as below:

请帮我看看如下结果:

按日期排序记录,然后按项目ID排序

Here is the Data table http://sqlfiddle.com/#!9/f2358/5

这是数据表http://sqlfiddle.com/#!9/f2358/5

2 个解决方案

#1


0  

I think that @Shadow is correct. Try this:

我认为@Shadow是正确的。尝试这个:

SELECT payment_date, project_id FROM `payments` ORDER BY project_id DESC, payment_date DESC

#2


0  

Firts order by should be payment_date (DES) and then projcet_id

第一个订单应该是payment_date(DES),然后是projcet_id

SELECT payment_date, project_id FROM `payments` 
ORDER BY payment_date DESC, project_id DESC

Otherwise if you want firts order by project and the for the same project ny payment

否则,如果您希望按项目订购第一项订单,并为同一项目付款

SELECT payment_date, project_id FROM `payments`
ORDER BY  project_id DESC,   payment_date DESC

#1


0  

I think that @Shadow is correct. Try this:

我认为@Shadow是正确的。尝试这个:

SELECT payment_date, project_id FROM `payments` ORDER BY project_id DESC, payment_date DESC

#2


0  

Firts order by should be payment_date (DES) and then projcet_id

第一个订单应该是payment_date(DES),然后是projcet_id

SELECT payment_date, project_id FROM `payments` 
ORDER BY payment_date DESC, project_id DESC

Otherwise if you want firts order by project and the for the same project ny payment

否则,如果您希望按项目订购第一项订单,并为同一项目付款

SELECT payment_date, project_id FROM `payments`
ORDER BY  project_id DESC,   payment_date DESC