Saving For Christmas

  • Discounted CEILING totally as the question was specific to round down.

  • Points awarded back for the typo in the question.

    My apologies.

  • The following query will allow coffee to be listed as a positive number and the recharge to be listed as a negative number.

    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(SIGN(n)*FLOOR(ABS(n))) FROM mycte
    GROUP BY a;

  • As the question stands today, after steve's correction of they typo is quite bizarre.  I can easily write code to do what Steve says he wants to do, but none of teh proferred answers does what the question asks for.  The result with 6 nd -22 appears to be what the requirement asks for!

    The question says it wants the values to be rounded down and ignore the cents and also wants to do something with the deposits which are shown as negative - so presumably the things to be rounded down are not the deposits but the positive amounts, so the coffee total result should be 6, not 8 so using ceiling instead of floor produces the wrong answer.   The interesting question then is why is floor wrong?  I gues that depends on what the quetion intends to be done to the deposits - rounding the deposit number upwards, since it is shown as negative, reduces the mount deposited, so presumably it reduces the amount saved, but rounding it down with floor means increasing teh amount deposited to the next whole number which increases the amount saved as stated in teh requirement.

    Tom

  • Thanks, great question.
    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • As I read it...

    Ceiling appropriate for the coffee card tracking

    You actually spent $6.91 but are recording it as $8.00 ($1.09 "saved" via obfuscation -- but its on the coffee card)

    I recharge my card and record that I put $20.00 on it. However, I actually put $20.75 on it ($0.75 "saved" via obfuscation -- also on the coffee card)

    However, the "savings" ends up on the coffee card, not in the savings account.

    I take it you can use your coffee card for gift shopping 😛

Viewing 6 posts - 16 through 20 (of 20 total)

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