Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Help with Query

Author  Topic 

chaaru_akilan
Starting Member

16 Posts

Posted - 2013-07-05 : 03:57:47
Hi I have a table as below,

UserID Date Usage
1 22/03/2013 97.99
1 22/03/2014 83.99
1 23/03/2013 75.99
1 23/03/2013 81.99
2 25/03/2013 66.99
2 25/03/2013 66.99
2 26/03/2013 55.99

I need to calculate the average usage for a user per day.

Output would be:
UserID Date Usage
1 22/03/2013 90.99
1 23/03/2013 78.99

I have got the distinct dates but am not able to iterate through the dates.Please help!

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-05 : 04:06:16
[code]
SELECT UserID,
[Date],
AVG(Usage) AS AvgUsage
FROM Table
GROUP BY UserID,
[Date]
ORDER BY UserID,
[Date]
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -