Need some SQL help - think it's simple

Author Message
Neiro
  • Total Posts : 37
  • Scores: 0
  • Reward points : 11230
  • Joined: 1/20/2011
  • Location: Denmark
Need some SQL help - think it's simple - Friday, March 16, 2012 5:27 AM
0
Hi. I have the following query, which lists people and how much they've been using specified software. Problem is, that I don't know how to add the time spent together - it's saved per computer it's been used on appearently. So I'm getting a lot of repeated names in the report, making it rather useless.
 
How do I add the UsageTime together before rounding it?
 
 select v_R_User.displayName0 as "Bruger",
 v_MeteredUser.FullName as "Brugernavn",
 replace(max(ou.User_OU_Name0),'ITCSYD.LOCAL/BRUGERE/','') as OU,
 round(v_MonthlyUsageSummary.UsageTime/60.0,2) as "Forbrug (min)"
 from v_R_System
 join v_MonthlyUsageSummary on v_R_System.ResourceID=v_MonthlyUsageSummary.ResourceID
 join v_MeteredFiles on v_MonthlyUsageSummary.FileID=v_MeteredFiles.MeteredFileID
 join v_MeteredUser on v_MonthlyUsageSummary.MeteredUserID=v_MeteredUser.MeteredUserID
 join v_R_User on v_R_User.Unique_User_Name0=v_MeteredUser.FullName
 left join v_RA_User_UserOUName ou on ou.ResourceID = v_R_User.ResourceID
 where v_MeteredFiles.ProductName = @RuleName
 group by v_R_User.displayName0,v_MeteredUser.FullName, v_MonthlyUsageSummary.UsageTime,ou.ResourceID
 order by  v_R_User.displayName0
 


gjones
  • Total Posts : 2291
  • Scores: 136
  • Reward points : 97970
  • Joined: 6/5/2001
  • Location: Ottawa, Ontario, Canada
Re:Need some SQL help - think it's simple - Friday, March 16, 2012 6:40 AM

Neiro
  • Total Posts : 37
  • Scores: 0
  • Reward points : 11230
  • Joined: 1/20/2011
  • Location: Denmark
Re:Need some SQL help - think it's simple - Friday, March 16, 2012 6:47 AM
0
Not sure what does happen, but not the intended effect.
One user has only run a given program once. For a total time of  37,88 and after adding the sum it'll be listed as 227,3 - I'm not sure why

Neiro
  • Total Posts : 37
  • Scores: 0
  • Reward points : 11230
  • Joined: 1/20/2011
  • Location: Denmark
Re:Need some SQL help - think it's simple - Friday, March 16, 2012 8:23 AM
0
Bit more investigating .... when doing a select * from v_MonthlyUsageSummary query the total usage time is listed as 2273 for that user that only used the software once. However, if I run a sum(v_MonthlyUsageSummary.UsageTime) as "forbrug (min) I get 13638 as the number - which by dividing with 60 as the rounding does reduces the number to 227,3
When just using v_MonthlyUsageSummary.UsageTime it'll tell me the right number. I just don't understand why sum does this. But I know it's not useful
 
Edit: Tried the following (in the select part) as well, in case it was summarizing for all entries or something (select sum(mus.UsageTime) from v_MonthlyUsageSummary mus where v_MonthlyUsageSummary.MeteredUserID = mus.MeteredUserID) as "Forbrug (min)"
<message edited by Neiro on Friday, March 16, 2012 8:40 AM>

gjones
  • Total Posts : 2291
  • Scores: 136
  • Reward points : 97970
  • Joined: 6/5/2001
  • Location: Ottawa, Ontario, Canada
Re:Need some SQL help - think it's simple - Friday, March 16, 2012 6:54 PM
0
I looked at this and the issue is with OUs. Notice within the query that you are grouping by OU.ResourceID, a user can below to multiple OU... So... Try this. http://tinyurl.com/7zk8ezt

Neiro
  • Total Posts : 37
  • Scores: 0
  • Reward points : 11230
  • Joined: 1/20/2011
  • Location: Denmark
Re:Need some SQL help - think it's simple - Monday, March 19, 2012 4:15 AM
0
Thank you man! that works!