On p.id = pe.participant_id) as percentage , 100*count(p.id)/(SELECT count(p.id) FROM participants as p JOIN participants_events as pe So i.signori answer will be : SELECT count(p.id) as count TO SELECT count(p.id) as count, round(100*count(p.id)/(SELECT count(p.id) FROM participants as p JOIN participants_events as pe on p.id = pe.participant_id),1) as percentage, p.Nationality So modify your initial query from : SELECT count(p.id) as count, round(100*count(p.id)/(SELECT count(p.id) FROM participants as p),1) as percentage, p.Nationality Please check in your initial query to use the same sets: HAVING round(100*count(p.id)/(SELECT count(p.id) FROM participants as p),1) <= 1 HAVING round(100*count(p.id)/(SELECT count(p.id) FROM participants as p),1) > 1įor the second part, try to combine the results of the first with those of the sum of percentages less than 1. , round(100*count(p.id)/(SELECT count(p.id) FROM participants as p),1) as percentage Try using Having clause: SELECT count(p.id) as count So with the new query the results will be: +-+-+-+ I want to modify the query in order to don't show any rows with percentage less than 1% but summarize their number and add is as 'Other' with the new percentage. JOIN participants_events as pe on p.id = pe.participant_id SQL file for betweeen query sql_between.This is the query I am using to get the percentage per country for participants in events: SELECT count(p.id) as count, round(100*count(p.id)/(SELECT count(p.id) FROM participants as p),1) as percentage, p.Nationality Selecting records between two date ranges
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |