MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old November 12th, 2003, 02:44 PM
gbarcalow gbarcalow is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 1 gbarcalow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Finding user with most calls by day.

So I have been working on this for 2 days now, and I am almost completly stuck.

I have a table Log_Main
Each record in the table represents a call that came into our office. Each record contains a Task_ID (Pri Key), a User_ID, a Call_Date, and other irrelivant data.

I need the query to count the number of calls each user has taken per day.. I got that part, here is the query for that.

SELECT Log_Main.User_ID, Log_Main.Call_Date, Count(*) AS Call_Count
FROM Log_Main
GROUP BY Log_Main.User_ID, Log_Main.Call_Date
ORDER BY Log_Main.User_ID

now from this data I want to select a distinct date, the user with the most calls for that day, and the number of calls.

any help would be appreciated
thanks in advance.

Reply With Quote
  #2  
Old November 14th, 2003, 10:13 AM
smackmeister smackmeister is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 21 smackmeister User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i would use a temp tables to get this done. It may be ugly but it should work...

Declare @temp table (user_id int, call_date datetime, call_count int)

insert into @temp
SELECT LM.User_ID, LM.Call_Date, Count(*) AS Call_Count
FROM Log_Main LM
GROUP BY LM.User_ID, LM.Call_Date
ORDER BY LM.User_ID


declare @temp2 table (call_date datetime, call_count int)

insert into @temp2
select call_date, max(call_count)
from @temp
group by call_date


select t1.user_id, t1.call_date, t1.call_count
from @temp t1,
@temp2 t2
where t1.call_date = t2.call_date
and t1.call_count = t2.call_count

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Finding user with most calls by day.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway