Saving For Christmas

  • Comments posted to this topic are about the item Saving For Christmas

  • These guys had a similar idea...but investing the "rounding"....

    https://acornsau.com.au/

  • In my opinion there is no right answer to choose.
    If we are using CEILING instead of FLOOR we will scrap the result of 'Coffee'. The FLOOR(ABS()) is a much more proper answer, as it removes the sign of the 'Recharges' only.

  • palotaiarpad - Tuesday, August 22, 2017 12:08 AM

    In my opinion if we are using CEILING instead of FLOOR we will scrap the result of 'Coffee'. The FLOOR(ABS()) is a much more proper answer, as it removes the sign of the Recharges only.

    Agree. The question says "round down" for coffee, but then you are going to use CEILING to round up for coffee?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • The only proper answer would be:
    SIGN(n)*FLOOR(ABS(n))

  • The question clearly says "For each amount, I want to round down and ignore the cents" surely ceiling is the opposite of this or have I misunderstood something? Perhaps something like:

    WITH

    mycte (a, n)

    AS (SELECT a, n FROM (VALUES ('Coffee', 2.38), ('Coffee', 4.53), ('Recharge card', -15.50), ('Recharge card', -5.25)) a (a, n) )

    SELECT a, SUM(round(n,0, 2)) FROM mycte

    GROUP BY a;

    And I think it is possible to get the answer using ABS().

    ...

  • The question is a very good example of what happens when your requirements are poorly expressed.

  • These questions certainly require a fair bit of mind reading to get "correct". But remembering the debacle from the previous installment and the following discussion, CEILING will accomplish what Steve is looking for. Purchases rounded up to look bigger, and deposits having decimals removed to look smaller.


    Just because you're right doesn't mean everybody else is wrong.

  • A few weeks ago 'Floor' was the right answer as well: http://www.sqlservercentral.com/questions/FLOOR()/160011/

  • The question says "round down" for coffee, but then you use CEILING to round up for coffee?

  • Question should read "round UP" for coffee. Agree with the others, the wording of the question is not the best!

  • I want my points back.  This question was as badly conceived as the other coffee card question a couple weeks ago.  The only reasonable answer is to use FLOOR(ABS(n)), and then remember which item (charge/deposit) should be considered negative.

    And if you want to keep track of the balance on your coffee card, wouldn't you subtract purchases and add deposits?  So if the balance is positive you can afford more coffee.

  • Like some business requirements I encounter in the real world, I read the question a few times.  I also picked the SUM(FLOOR(ABS(n))) answer.  I must say, however, that I like the recurring theme, but interpretation of the question is ambiguous, just like real-world requirements can be.

    I think the better answer would be to skip integration with the coffee fund, start a Christmas account and automatically transfer funds at a predefined interval from the main checking account into the Christmas fund. 😉

  • Déjà vu much?
    somewhat vague and confusing requirement, leading to a vague and confusing result....

    might've got it wrong, but still reiterated the CEILING/FLOOR functions. thanks Steve...

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • I am totally confused, just as I was on July 31, 2017 when a similar question was asked.
    But now the answers don't match either which makes it even more confusing.
    I don't even like coffee.  I should just skip these coffee questions.

Viewing 15 posts - 1 through 15 (of 20 total)

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