Get the average of the data in the table.

  • 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.

  • Try:

    select [Day], AVG([Value] as Avg_Value

    from [MyTable]

    group by [Day]

    Hope this helps.

  • 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]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply