Repeating Formulae

  • the following statement doesnt seem to work:

    select

    gym + park + hall as mysum,

    3 * mysum + 56 as mysum_processed

    from my_table

    To get it to work I need to do the following:

    select

    gym + park + hall as mysum,

    3 * (gym + park + hall) + 56 as mysum_processed

    from my_table

    this seems INEFFICIENT to me as I am repeating my gym + park + hall formula.

    Do I have to repeat the formula???

    Thanks in advance!

    Eamon

  • I'm afraid you do have to repeat it. One way around it would be to use a subquery in the FROM clause, but I don't know about performance.

    
    
    select mysum,
    3 * mysum + 56 as mysum_processed
    from (select gym + park + hall as mysum
    from my_table) my_der_table
  • thanks npeeters. Looks like we have to live with it.

    strange that this is so as it seems so straightforward to do:

    select

    gym + park + hall as mysum,

    3 * mysum + 56 as mysum_processed

    from my_table

    -- well done to the Belgian tennis girls (clijsters and Hannan)

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

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