Help with percentage calculation

  • I can't seem to wrap my head around this!!

    tblReturn: colAcct, colSector, colAdate, colMkt

    I want to return this percentage:

    (colMkt where colSector = 02 / colMkt where colSector = TF)

    Any help pointing me in the right direction would be gladly appreciated.

  • select sum(case when colSector ='02' then colMkt else 0 end)/sum(case when colSector ='TF' then colMkt else 0 end) as percentage

    from tblreturn

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • To avoid "Division by 0" error it's better to use "else NULL" instead of "else 0".

    _____________
    Code for TallyGenerator

  • Sergiy (4/29/2008)


    To avoid "Division by 0" error it's better to use "else NULL" instead of "else 0".

    correct! wasn't paying attention.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thanks for your help- I was able to get the info I needed.

Viewing 5 posts - 1 through 4 (of 4 total)

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