If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > More complicated use of aggregates...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-05, 06:14
shiv_379 shiv_379 is offline
Registered User
 
Join Date: May 2005
Posts: 21
Red face More complicated use of aggregates...

Greetings all!
I am stuck with something at the moment, and that added to the cold thats got me in its icy grip is really batting my head
Basically I have a table of records:
Record_ID (id) | Employee_ID (pin) | Record_type (msgtype) | record_date | record_time (logtime)
What I am looking for is, for each employee_ID on a specific day, the Record_ID of the earliest record of type '5'. I've only got one date in there at the moment so thats not such a problem. My attempt was:

Code:
SELECT combined.ID
FROM combined
GROUP BY combined.pin
HAVING min(logtime);
but that didnt work, complaining that combined.id is not in the group by.

Can anyone provide any suggestions?

Thanks!
~Shiv

EDIT: Forgot to mention, I'm using MS Access....
Reply With Quote
  #2 (permalink)  
Old 12-02-05, 06:35
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Perhaps something like this (or its variations - I'd say that interesting part is the use of a subquery):
Code:
select c.employee_id, c.record_id
from combined c
where c.logtime = (select min(c1.logtime) 
                   from combined c1
                   where c1.employee_id = c.employee_id
                  )
  and c.record_type = 'S'                  
group by c.employee_id, c.record_id;
Reply With Quote
  #3 (permalink)  
Old 12-02-05, 06:42
shiv_379 shiv_379 is offline
Registered User
 
Join Date: May 2005
Posts: 21
Cool, I'm giving that a go so I'll let you know how it works out. It's gotta go through about just under a million records, so its taking a while!!!
~T
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On