Hi i have a table with the following fields ‘Site Code’ ‘Date’ ‘Hour’ ‘Quantity’ and i want in a query to take all the inputed data of the last week. But there can be more than one inputs for one date so i will have to group according to Date first and then order those groups in DESC and take the last 7. The query i am using however does not work as it should because it orders the groups but in days with multiple inputs i am getting only 1 of them.
the query is:
SELECT `Quantity` , `Hour` , `Date`
FROM (
SELECT *
FROM `13_trans_coffee`
WHERE `Site Code` =103713
GROUP BY `Date`
ORDER BY `Date` DESC
)days
LIMIT 0 , 7
sample data
site code date hour quantity
103713 5/12/2011 0:00 21 10
103713 5/12/2011 0:00 20 11
103713 4/12/2011 0:00 14 10
103713 6/12/2011 0:00 20 10
103713 8/12/2011 0:00 23 10
notice i have 2 inputs for day 5/12/2011 but the results of the query are
quantity hour date
10 23 8/12/2011 0:00
10 20 6/12/2011 0:00
11 20 5/12/2011 0:00
10 14 4/12/2011 0:00
one input is missing.
The below one should work.