July 15, 2017 at 11:43 pm
Comments posted to this topic are about the item The Missing Price
July 15, 2017 at 11:46 pm
Good question thanks Steve, but do I detect two possible answers, which is why the responses fall into two categories (at least so far)?
...
July 16, 2017 at 5:51 pm
What a disastrously wrong QOTD!
The official answer (about types) is a small part of the correct answer, and the genuinely correct answer is another of the answer options! One doesn't even need to change the stored type to fix the stupid typing, just changing the literal division from 100 to 100.00 has exacty the same effect as tthat with no table type changes, but still delivers wrong results, because the way the calculation is expressed subtracts the absolute value of the percentage (eg for 5 per percent 0.05) insted of the product
Forcing decimal instead of integer arithmetic won't deliver the correct answer, because the given calculation is just plain wrong. Changing the literal divisor from 100 to 100.00 (which forces everything to be converted from int to decimal so that the whole calculation works in decimal) fices the type issue without needing to fix the silly types in the table. But fixing the type issue doesn't deliver correct results. The calculation shown subracts the absolute value of the percentage, not the value of the product of the percentage with the total percentage value.
Or to express it bluntly in tidy notation: X-D/100.00 is usually not the same number as X * (1-D/100.00) and it is just plain crazy for a QOTD to claim that those two calculations deliver the same result.
So to date, 30 % of answers have been correct and been awarded no points, while 70 percent of answers have been wrong (because changing the type doesn't fix the problem) and have been awarded points. It looks as if the majority need to be taught elementary arithmetic, but are being encouraged not to learn it, while the minority who understand it are taught that it is wrong.
Tom
July 16, 2017 at 6:04 pm
HappyGeek - Saturday, July 15, 2017 11:46 PMGood question thanks Steve, but do I detect two possible answers, which is why the responses fall into two categories (at least so far)?
Yes, it's a good question. But the officially correct one of those two is in fact wrong, and the officially wrong one is in fact correct. It's a good question, but a terrible (wrong) answer and explanation.
I'll be surprised if anyone anwers anything other than one of those two answers, but I guess it could happen, some may (oh horror of horrors) select one of the other two.
Tom
July 16, 2017 at 10:29 pm
TomThomson - Sunday, July 16, 2017 6:04 PMHappyGeek - Saturday, July 15, 2017 11:46 PMGood question thanks Steve, but do I detect two possible answers, which is why the responses fall into two categories (at least so far)?Yes, it's a good question. But the officially correct one of those two is in fact wrong, and the officially wrong one is in fact correct. It's a good question, but a terrible (wrong) answer and explanation.
I'll be surprised if anyone anwers anything other than one of those two answers, but I guess it could happen, some may (oh horror of horrors) select one of the other two.
Tom
Absolutely concur with everything you have said for the same reason, it came down to; are we being asked how to formulate a correct discount value or about data types, I figured whichever was answered it would be wrong!! In the end I just decided "I hope I am not being taught basic math!"
...
July 17, 2017 at 1:23 am
Sorry, not such a good question. 🙁
5ilverFox
Consulting DBA / Developer
South Africa
July 17, 2017 at 1:51 am
TomThomson - Sunday, July 16, 2017 5:51 PMIt looks as if the majority need to be taught elementary arithmetic, but are being encouraged not to learn it, while the minority who understand it are taught that it is wrong.
As one of the majority, another possibility is that we guessed at the answer most likely to be "correct" in order to get to this discussion 😉
July 17, 2017 at 2:56 am
Given that there is no table definition, we have no way of knowing that the fields are integers.
July 17, 2017 at 3:16 am
andrew_dale - Monday, July 17, 2017 2:56 AMGiven that there is no table definition, we have no way of knowing that the fields are integers.
That was my thought as well - there were two valid answers, and fixing neither of them on their own would have resolved the query for the correct intent.
One could assume that the data columns were integers purely because of the output format, however this can vary with options and the tools used.
However the formula was incorrect regardless of the data format.
So I got a "wrong answer" score despite picking up the fact that the formula was incorrect, I had to choose one of them but the law of 50/50 leapt in as usual 🙂
July 17, 2017 at 3:28 am
n.ryan - Monday, July 17, 2017 3:16 AMThat was my thought as well - there were two valid answers, and fixing neither of them on their own would have resolved the query for the correct intent.
That's true, but the only explanation for the given result is that the data types are integers. The answer "The discount percentage calculation is incorrect" is correct, but it doesn't give that result.
July 17, 2017 at 5:27 am
I have to go with the 'calculation is wrong' group. While the integer vs decimal part is also a problem, the first and foremost problem is the calculation is dead wrong and would never provide a correct result. Now if part of the intention was to have an incorrect calculation as a distraction from the integer vs decimal piece of the puzzle then bravo, point taken.
However a simpler question to make the same point would be more like
why does select 5/10 not = .5?
Just saying....
July 17, 2017 at 7:11 am
Holy cow people. Pretty nasty responses to the QOTD. In fact the ONLY possible right answer to the question is the one about datatypes. Yes the calculation is incorrect but that is not relevant to the question being asked here. It states that the query provided a certain set of results, it did NOT state that the results were incorrect. The question was why are the results what they are. Perhaps a correct calculation but still having the integer division issue would have been better but given the verbiage of the question there is only one possible correct answer. The fact that the calculation is incorrect is something entirely different.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 17, 2017 at 7:36 am
Heh, well, to be fair, the question is incredibly vague.
It's "Why do I get the result I get?"
The are many factors that combine to get this particular result.
Yes, it is true that the behavior of integer division contributes to this result (i.e., the result would be different if DiscountPercentage were not an integer and DiscountPercentage/100 returned something non-zero, or if the literal were 100.0).
However, the same is true of the calculation being incorrect. If the calculation were correct, the results would also be different.
You need both of the integer division behavior and this particular incorrect calculation to get these results.
Each is only a partial explanation of why we get the particular results we get.
If the question had been "Why do I get these values for FinalCost, instead of 50.00, 199.95, and 1099.90 (my expected results)?" Then absolutely, the current answer would be the only correct one.
As it stands, though it's a poor question/answer set.
Cheers!
July 17, 2017 at 8:11 am
The calculation is wrong is ALSO the correct answer.
July 17, 2017 at 8:26 am
Bobby Russell - Monday, July 17, 2017 8:11 AMThe calculation is wrong is ALSO the correct answer.
The calculation is not going to produce the desired output but the question clearly asks why are they getting the result they are getting. It does not say what is wrong with the query.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply