Precedence in math

  • bitbucket-25253 (1/10/2013)


    SQLRNNR (1/9/2013)


    I completely disagree.

    Only for the sake of creating discord, malcontent, and to be argumentative because there is nothing in the question to whine about otherwise.

    Thanks - so use to getting lots of discord, malcontent and whines that I was beginning to think that I just might have turned over a new leaf so to speak - horrors loosing my reputation !!

    😀 Glad you liked that

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Precedence in mathematical operations was the second theme I saw in my first day at the programming class. The first was data types in Turbo Pascal 3.0.

    Thanks for making me remember old and good times with this question. 🙂

  • call.copse (1/10/2013)


    While it does appear to just test basic maths, I'd argue that doing an example without brackets is just annoying, and I'd be pretty displeased if debugging someone's SQL who had not bothered to put in some brackets for anything except basic addition / subtraction. Still I suppose something could have been done to spice it up, but I guess I'm not coming up with anything *shrugs*

    I agree with call.copse that while awareness of the rules is handy, it would only be good practice to code multiple operand expressions with parentheses. Why leave a speed bump for human comprehension in your code? Which has the more obvious result: A + B * C, or A + (B * C)? Sure, you may know the rules, and so may your sucessor in maintaining a program, but this is a good area in which to remember to KISS.

  • It pains me to say that in 10 years from now, there will be a whole lot more wrong answers. Many smart high school students would just whip out their TI-89 calculators, before trying to think it thru. Even one of the highest rated public colleges in the US has for-credit (i.e. not considered remedial) math courses that cover what was previously taught in 11th grade. I say this from my experience as a parent of students of that approximate age demographic.

  • Hugo Kornelis (1/10/2013)


    If this is an easy starter for a series of questions that gradually builds up, then it's sort of okay - though probably TOO easy.

    As a stand alone question, I am not excited about it. The use of parentheses in all the queries means that there is no ambiguity anywhere, even for those who don't know the rest of the arithmetic precedence rules (and I would hope that almost everyone would get the question right even if there were no parentheses used in some of the queries).

    Also, why use a blog post as the only reference, when a 5 second Google search would have given you this Books Online link?

    Hugo, I agree except for one thing. As a stand alone question this is a excellent example of making something appear very easy to the reader when it could have been written differently and more would have been challenged. Again I agree that it is easy, but that in itself is the point. Simplicity can make the life of the maintainer or even your revisiting the SQL easier if a little effort is given.

    M.

    Not all gray hairs are Dinosaurs!

  • Great QotD. Ron. Thanks!

  • Back to basics..this was required..lot of us just forget the basics.....

  • BODMAS .... PEDMAS

    both are same right?

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

  • Raghavendra Mudugal (1/11/2013)


    BODMAS .... PEDMAS

    both are same right?

    Yes

    In India we use BODMAS (Brackets, Order , Divide, Multiply, Add, Subtract)

    In USA it is PEMDAS (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction)

  • Unbelievable, 98% of right answers! I think it's the record on ssc.

    Next, I will submit the following question:

    What color was the Napoleon's WHITE horse?

    😛

  • Carlo Romagnano (1/11/2013)


    Unbelievable, 98% of right answers! I think it's the record on ssc.

    Next, I will submit the following question:

    What color was the Napoleon's WHITE horse?

    😛

    ummm.... Green?

    .

    no wait.... RED?

    .

    .

    .

    black?

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

  • Raghavendra Mudugal (1/11/2013)


    Carlo Romagnano (1/11/2013)


    Unbelievable, 98% of right answers! I think it's the record on ssc.

    Next, I will submit the following question:

    What color was the Napoleon's WHITE horse?

    😛

    ummm.... Green?

    .

    no wait.... RED?

    .

    .

    .

    black?

    What type of White it is? Pure White or Cream.. or Grayish....

  • Bangla (1/11/2013)


    What type of White it is? Pure White or Cream.. or Grayish....

    I'll have to go for Paul White. 😉


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • We are making fun on a such valuable basic question. Eventhough its easier one, it will be very useful for beginners..

    If we started making fun like this on simple questions, surely it's going to be a discouraging factor for the beginners to post new questions..

    --
    Dineshbabu
    Desire to learn new things..

  • Hugo Kornelis (1/11/2013)


    Bangla (1/11/2013)


    What type of White it is? Pure White or Cream.. or Grayish....

    I'll have to go for Paul White. 😉

    which one? http://en.wikipedia.org/wiki/Paul_White or http://www.sqlservercentral.com/Authors/Articles/Paul_White/46040/

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

Viewing 15 posts - 31 through 45 (of 58 total)

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