Mysql查询 - 按工作顺序排序

时间:2010-04-18 13:04:09

标签: php mysql

我正在运行Mysql 5.0.77,我很确定这个查询应该有用吗?

SELECT * 来自purchases time_purchased BETWEEN'2010-04-15 00:00:00'和'2010-04-18 23:59:59' ORDER BY time_purchased ASC,order_total DESC

time_purchased是DATETIME和索引。

order_total是DECIMAL(10,2),而不是索引。

我想按日期(最少到最大)订购所有购买,然后按订单总数(最大到最少)订购。

所以我的输出类似于:

2010-04-15 $ 100

2010-04-15 $ 80

2010-04-15 $ 20

2010-04-16 $ 170

2010-04-16 $ 45

2010-04-16 $ 15

2010-04-17 $ 274

..等等。

我从该查询获得的输出正确地按顺序排列日期,但它似乎根本不对订单总计列进行排序。想法?

感谢。

1 个答案:

答案 0 :(得分:3)

SELECT date(time_purchased), order_total
FROM purchases 
WHERE time_purchased BETWEEN '2010-04-15 00:00:00' AND '2010-04-18 23:59:59' 
ORDER BY date(time_purchased) ASC, order_total DESC