开发者

Mysql Query - Order By Not Working

开发者 https://www.devze.com 2022-12-27 20:02 出处:网络
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\'

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

精彩评论

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