2021年3月30日星期二

How to output decimal value vs integer?

I am trying to understand the optimal methods to output decimals or percentages when running division in sql.

select amount / tips as value    expected output: .20    select amount / tips as value_percent     expected output: 20  

above will give me 0 since calculation gives .2 but wanted to understand how to account for that? Thanks

Additional question:

I have been given query below as:

select ROUND(100.0 * COUNT(DISTINCT c.user_id) / COUNT(DISTINCT b.user_id)) AS browse_to_checkout_percent  

what is the round doing here as there is no ,2 parameter for decimal points to round to? and is 100.0 the same thing as using cast as decimal?

what is the optimal method to retrieve the output values as .2 or if percent 20? It is confusing to me as I have seen * 1.0 or cast as decimal with a round but am not sure what the best methods are? Thanks

https://stackoverflow.com/questions/66880761/how-to-output-decimal-value-vs-integer March 31, 2021 at 10:15AM

没有评论:

发表评论