Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

sql code query!

Options
  • 10-05-2006 1:25pm
    #1
    Closed Accounts Posts: 1,723 ✭✭✭


    Hey I have two select statements below, how do i join them so an extra two columns for "b" and "c" are created.

    Select Count(*), AVG(INT_RTE), SUM(BAL_AMT), SUM(NET_BAL)
    FROM filenamexxx

    WHERE bal_for_int > 0
    and bal_for_int<1000
    And load_last_act<>'d'
    and(period_date='date')

    For the above, i want an extra column created and populated with the value 'B'. So there will be five colums i.e COUNT, INT RATE, BAL AMT, NET BAL and then one added say INT_BAND to be populated with the value B.

    Then i have abother select statement below, but want to join this into the first one so i will have a row underneath the above with the value C populated

    Select Count(*), AVG(INT_RTE), SUM(BAL_AMT), SUM(NET_BAL)
    FROM filenamexxx

    WHERE bal_for_int > 10001
    and bal_for_int<2000
    And load_last_act<>'d'
    and(period_date='date')


    So the table result will be:

    COUNT
    INT RATE --- BAL AMT---NET BAL -- INT_BAND
    133232--- 1123333 --- 3232332 --- 32324 --- B
    121324--- 233323 ---- 232323 ----655655 -- C


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    This should do what you want
    Select Count(*), AVG(INT_RTE), SUM(BAL_AMT), SUM(NET_BAL),'B' AS INT_BAND
    FROM filenamexxx

    WHERE bal_for_int > 0
    and bal_for_int<1000
    And load_last_act<>'d'
    and(period_date='date')
    UNION
    Select Count(*), AVG(INT_RTE), SUM(BAL_AMT), SUM(NET_BAL),'C' AS INT_BAND
    FROM filenamexxx

    WHERE bal_for_int > 10001
    and bal_for_int<2000
    And load_last_act<>'d'
    and(period_date='date')


  • Closed Accounts Posts: 1,723 ✭✭✭empirix


    works a treat, thanks really appreciated


Advertisement