I would like to GROUP BY an item in my table, which has an associated monetary value. This I can work out as a percentage, however there are often too many items in the list (too many to be useful, for example in a graph). Consequently, I would like to put those items that have a contribution to the total of less than say 5% into an ‘Other’ group. Any thoughts?
thanks (using MySQL > v5)
Looks like a UNION could help, e.g. (depending how your table’s organized, of course):
If you don’t have a percent field but only (say) a value field (so the % needs to be dynamically computed as 100 times the fraction of an item’s value to the grand total) you can get the grand total from yet another nested SELECT, but at some point it may be worth switching to procedural approaches as other respondents hint.