我想先按日期排序结果,然后按id排序。
我使用了查询
SELECT payment_date,project_id FROM `payments` ORDER BY payment_date desc, project_id desc
但它没有用。我想首先按日期对数据进行排序,并获得在第一行下面的记录之后有最大日期的项目ID,根据特定的项目ID显示所有日期。
喜欢
请帮助我得到如下结果:
答案 0 :(得分:0)
我认为@Shadow是正确的。试试这个:
SELECT payment_date, project_id FROM `payments` ORDER BY project_id DESC, payment_date DESC
答案 1 :(得分:0)
Firts order by应为payment_date(DES),然后是projcet_id
SELECT payment_date, project_id FROM `payments`
ORDER BY payment_date DESC, project_id DESC
否则,如果您想按项目订购第一项订单,并且需要同一项目付款
SELECT payment_date, project_id FROM `payments`
ORDER BY project_id DESC, payment_date DESC