calculating avg

  • I have a situation where I need to calculate the avg sal only when I have a recent value.

    i.e,

    table:

    id reportingperiod sal

    1 jan 2000

    1 aug 2200

    2 jan 2000

    2 aug 0

    I want the result to be:

    id avg(sal)

    1 2100

    2 0

    I tried alot using case statements but I think I am missing some thing there..

    Please help me...

    Thanks.

  • is reportingperiod actually a char data type or is it a date data type?

  • Its a character data type

  • with a datetime it would be easy to work out what the most recent value, with characer field it would be more difficult do you have any columns that would define what a recent value is?

  • NO 🙁

    I donot have any other column which defines the reportingperiod..

  • Is there any specific reason for starting two threads with the identical issue within one hour?

    (http://www.sqlservercentral.com/Forums/FindPost1049494.aspx) :angry:



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • No further replies to this thread please.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 7 posts - 1 through 6 (of 6 total)

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