Quantcast
Channel: Select query returns 0 for calculating percentage using division operator
Viewing all articles
Browse latest Browse all 4

Select query returns 0 for calculating percentage using division operator

$
0
0
This is because of the integer division. You can cast one of the operands to DECIMAL with correct precision, or simply
do something like this:

SELECT (group_total * 1.0/total) * 100 FROM transfer_out_summary;


Cast example:
SELECT (group_total / CAST(total AS DECIMAL(10, 2))) * 100 FROM transfer_out_summary;


--
Plamen Ratchev
http://www.SQLStudio.com

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>