Log in

View Full Version : Agregate function



nedy_03
02-07-2008, 03:46 AM
Hello,

I am facing this situation. I have a table called "CALLTRACE". The columns are:
- CalltraceID
- QueueID
- AgentID
- CloseTime
- CallCode
- DialedNO
- LeadID

To a LeadID may corispond more then one DialedNo,CloseTime, DialedNo,AgentID

I would need a query that returns the LeadID with the latest ClodeTime. For that I used this sintax:
SELECT leadid,max(calltrace.closetime)as Last_time
FROM calltrace
WHERE queueid=8
GROUPBY leadid
Orderby'Last_time'

But I would need to add to every row the corisponding DialedNo, CallCode and AgentID.

Cloud someone help me with that issue pls?!!

Thx,
Nedy

rconverse
02-07-2008, 11:25 AM
Hello,

I am facing this situation. I have a table called "CALLTRACE". The columns are:
- CalltraceID
- QueueID
- AgentID
- CloseTime
- CallCode
- DialedNO
- LeadID

To a LeadID may corispond more then one DialedNo,CloseTime, DialedNo,AgentID

I would need a query that returns the LeadID with the latest ClodeTime. For that I used this sintax:
SELECT leadid,max(calltrace.closetime)as Last_time
FROM calltrace
WHERE queueid=8
GROUPBY leadid
Orderby'Last_time'

But I would need to add to every row the corisponding DialedNo, CallCode and AgentID.

Cloud someone help me with that issue pls?!!

Thx,
Nedy


If you are just looking to pull in more fields, then pull them in.


SELECT leadid,max(calltrace.closetime)as Last_time, DialedNo, CallCode, AgentID
FROM calltrace
WHERE queueid=8
GROUPBY leadid, Last_time, DialedNo, CallCode, AgentID
Orderby'Last_time'


HTH
Roger