[Solution] SQL Division

Click here to view the question


Solution:

Multiply the numerator by 1.0

select
  platform
  , active_users
  , total_users
  , active_users * 1.0 / total_users as percent_active_users
from
  user_summary

 

Concepts Covered: Integer Division

Explanation:

In SQL, dividing 2 integers returns an integer. A quick way to resolve this is to multiply the numerator by 1.0. This divides a float by an integer, returning a float output.

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 11 mths agoLast active
  • 311Views
  • 1 Following