View Full Version : pivot tables


nmp2725
01-09-2002, 12:32 PM
I have a crosstab query to produce a list of locations with the number of instances recorded per month over a 365 day rolling period.
Is there a way to order the months correctly eg. 11-2001, 12-2001, 1-2002
currently the 1-2002 comes straight after 1-2001.

The code is shown below
TRANSFORM Count(*) AS Incs
SELECT main_data.location_id, location_count.total_incs
FROM main_data, location_count
WHERE main_data.time_date > (now()-365) and
main_data.location_id = location_count.location_id and
location_count.total_incs > 50
GROUP BY main_data.location_id, location_count.total_incs
ORDER BY location_count.total_incs desc
PIVOT Format(time_date,"mm-yyyy");

David R
01-09-2002, 01:28 PM
One possibility is to format it as yyyy-mm instead. Then the year will be checked first. Not sure if it's what you're looking for.

HTH,
David R