mysql - SQL select percentage -


i have 2 tables in mysql hold users , 1 holds there subscriptions. there users may sign not subscribe. use following query count of users have not subscription:

select count(social_users.id) social_users left join socials on social_users.id = socials.social_user_id socials.social_user_id null 

the above query works fine , return number count of users have no subscription.

now, want there percentage relative total number of users. tried make 2 count sql queries , divide them follows:

(select count(social_users.id) social_users left join socials on social_users.id = socials.social_user_id socials.social_user_id null) / select count(social_users.id) social_users 

however, query not work. need know other way allow me embed 2 select , divide them , multiply result 100.

try this

   select ( (select count(social_users.id) social_users left join socials on     social_users.id = socials.social_user_id socials.social_user_id     null) / (select count(social_users.id) social_users))*100 percentage 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -