开发者

Mysql Query - Order By Not Working

I'm running Mysql 5.0.77 and I'm pretty sure this query should work?

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

time_purchased is DATETIME, and an index.

order_total is DECIMAL(10,2), and not an index.

I want to order all purchases by the date (least to greatest), and then by the order total (greatest to least).

So I would output similar to:

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

.. and so on.

The output I am getting from that query has the dates in order correctly, but it doesn't appear to sort the order total 开发者_Go百科column at all. Thoughts?

Thanks.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜