SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get the average of the data in the table.


Get the average of the data in the table.

Author
Message
Mithra
Mithra
SSC Journeyman
SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)

Group: General Forum Members
Points: 83 Visits: 428
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.
imex
imex
SSC Veteran
SSC Veteran (231 reputation)SSC Veteran (231 reputation)SSC Veteran (231 reputation)SSC Veteran (231 reputation)SSC Veteran (231 reputation)SSC Veteran (231 reputation)SSC Veteran (231 reputation)SSC Veteran (231 reputation)

Group: General Forum Members
Points: 231 Visits: 199
Try:

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



Hope this helps.

http://www.imoveisemexposicao.com.br
subbu1
subbu1
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1295 Visits: 695
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]
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search