views:

52

answers:

1

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.

+2  A: 
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
RedFilter
That does it, thanks.
jwzk