mysql按照月份排序_MySQL - 按日期排序ASC和DESC,具体取决于其他领域(MySQL - Order by date ASC and DESC, depending on other f...

I have these rows in a table...

id task_type task_date

1 1 01/15/2010

2 2 01/18/2010

3 1 01/18/2010

4 2 01/16/2010

6 1 01/16/2010

8 1 01/17/2010

9 2 01/17/2010

and I want to order them in a particular way: when task_type=1 order by ASC and when task_type=2 order by DESC

id task_type task_date

1 1 01/15/2010

6 1 01/16/2010

8 1 01/17/2010

3 1 01/18/2010

2 2 01/18/2010

9 2 01/17/2010

4 2 01/16/2010

Is this even possible? I've been looking for conditional queries and all i can get is a syntax error...

This is the query that i cant make it work properly:

SELECT id, task_type, task_date

From Tasks

ORDER BY CASE WHEN task_type=1 THEN

task_type ASC, task_date ASC, hour ASC, priority DESC, id ASC

WHEN task_type=2 THEN

task_type ASC, task_date DESC, hour ASC, priority DESC, id ASC

END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值