I am trying to calculate a percentage in my sql statement which gives a wrong answer
-
21-12-2019 - |
Question
This is my sql statement. The sum of callers total is: 322
and the sum of the other four is: 9966
. 322 / 9966 = 0,32
... Now my problem is that in sql it gives 2.2233
. Which is absolutely wrong. I use this also in one other place in which this works.
SUM(callers_total / (a.start_reached_speech_mobile + a.start_reached_speech_landline + a.start_reached_text + a.start_reached_email))
Really hope someone could clarify why this is going wrong because I really don't have a clue.
Solution
Try:
SUM(callers_total) /
SUM(a.start_reached_speech_mobile + a.start_reached_speech_landline + a.start_reached_text + a.start_reached_email)
OTHER TIPS
You're summing up all the percentages, it looks like. What happens if you get rid of the outer SUM
?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow