Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Get the average of the data in the table. Expand / Collapse
Author
Message
Posted Monday, October 15, 2012 7:23 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, August 16, 2014 12:36 PM
Points: 31, Visits: 378
Team,

I have a set of data for perticular day.Plesae help me in writing a sql query to get the average of the data for perticular day.

Table:
Day value
june 1 4
june 1 5
june 1 2
june 2 1
june 2 5
june 2 3


Ouput needed as below:

day avg value
June 1 3.6
june 2 3


As above i need a calculated average result for all the data for a perticualr day.Thanks in advance.

Post #1373009
Posted Monday, October 15, 2012 10:18 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, February 27, 2013 6:54 AM
Points: 40, Visits: 168
Try:

select [Day], AVG([Value] as Avg_Value
from [MyTable]
group by [Day]

Hope this helps.


http://www.imoveisemexposicao.com.br
Post #1373022
Posted Monday, October 15, 2012 10:26 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 1:04 AM
Points: 880, Visits: 670
try below code.....
declare @t1 table (day varchar(10),value int)
insert into @t1
select 'june 1',4
union all
select 'june 1',5
union all
select 'june 1',2
union all
select 'june 2',1
union all
select 'june 2',5
union all
select 'june 2',3
select [Day], AVG(convert(decimal(10),[Value])) as av
from @t1
group by [Day]
Post #1373023
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse