简体   繁体   中英

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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM