Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calculate a percentage of column by userid (SQL)

I have this really small table where I need to calculate
what percent of users used a time-off feature?
time_off_used parameters show if users used that feature (1), or not (0)

role user_id time_off_used
Admin 45ds4f5d4sfd5s5fd5s4dfg 0
Admin 45ds5f4ds5sdf45dfs5sdgfgf 1
Regular 45ds4f5d4sfd5s5fd5s4dfg 0
Admin dh454hkd564khdg564kd6fgjg 1
Project manager sgj3js32jgfsj1s2jss1jgssg54 1
Admin 45ds5f4ds5sdf45dfs5sdgfgf 1
Regular 45d34frty5d4sfd5s5fd5s4dfg 0
Admin dhy556gd564khdg564kd6fgjg 1
Project manager sgj3js32jgfsj1s2jss1jgssg54 1

I need just one number as a result, for example 70.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

simple as this :

select sum(time_off_used)* 100.0 / count(*) as percentage_used_feature
from tablename 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading