• Dineshbabu (2/6/2013)


    Raghavendra Mudugal (2/6/2013)


    so, if no brackets then just start from L to R no matter what the operator is... and in the above given equation we don't know where to place the brackets and it leads to follow traditional BODMAS (excluding the BO in the sequence)... correct ?

    Let's take our today's OoTD

    Statement A:

    SELECT (45 * (9 - 5 + 8)- 36 / 4)

    Brackets first. If we have nested brackets ,then inner most first.. So first we take

    (9 - 5 + 8)

    Addition and subtraction have same precedence. In that case go from Left to Right.

    (9 - 5 + 8) => (4+8)

    (4+8) =>12

    so the exprresion will look like "SELECT (45 * 12- 36 / 4) "

    Division and Multiplication has higher precedence over Addition and subtraction. So first Multiplication and divsion has to be done before + or -.

    45*12 =>540

    36/4 =>9

    Now the expression will be "SELECT (540- 9) "

    so final result is 531

    thanks, i have tried that in the morning and I got that, but my question (in my previous reply) was not using any brackets, so BODMAS concept (excluding BO) would apply with L to R move... i guess. (and was trying this below and I kind of answered my self...)

    SELECT 45 * 9 - 5 + 8- 36 / 4

    SELECT 45 * 9 - 5 + 8 - 9

    SELECT 405 - 5 + 8 - 9

    SELECT 405 - 6

    answer = 399

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.