GROUP BY multiple fields

johnseito

Registered User.
Local time
Yesterday, 23:13
Joined
Feb 27, 2013
Messages
89
and find the max and min?

How do you GROUP BY multiple fields and find the max and min of them?
I did it and could only do it to one field, if I add more field I would have an error.

this works fine
SELECT [Inspector First & Last Name],
[apt start date],
max([Uploaded Time]) as [max upload time]
FROM Original
GROUP BY [Inspector First & Last Name], [apt start date];
But this is not fine
SELECT [Inspector First & Last Name],
[apt start date],
min ([apt start time]) as [apt min start time]
max ([apt finish time]) as [apt max finish time]
max([Uploaded Dates]) as [max upload date],
max([Uploaded Time]) as [max upload time]


FROM Original
GROUP BY [Inspector First & Last Name], [apt start date];



Thanks, Appreciate it.
 
Your SELECT Statement should work after you correct a simple Syntax Error. Each Item being SELECTed must end with a Comma, except the last one. Your example is missing two of them (see below).
Code:
SELECT [Inspector First & Last Name], 
[apt start date], 
min ([apt start time]) as [apt min start time][COLOR=red][B],   <--- ADD This Comma[/B][/COLOR]
max ([apt finish time]) as [apt max finish time][B][COLOR=red],   <--- ADD This Comma[/COLOR][/B]
max([Uploaded Dates]) as [max upload date],
max([Uploaded Time]) as [max upload time]
FROM Original
GROUP BY [Inspector First & Last Name], [apt start date];
 
Good catch rookie, it is annoying when posters just say they have an error, my telepathic powers aren't upto it these days.

Brian
 

Users who are viewing this thread

Back
Top Bottom