Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MYSql Top 10 und andere insgesamt

Fürs Protokoll, ich stimme dem Kommentar von @DamienBlack zu, jedoch wenn es musste in einer Abfrage ein UNION ALL erfolgen könnte den Trick machen:

(
  SELECT VENDOR_fullname as name, SUM(POTENTIAL_RECOVERY) as recovery
  FROM COMPLETE
  GROUP BY VENDOR_fullname
  ORDER BY SUM(POTENTIAL_RECOVERY) DESC
  LIMIT 10
)
UNION ALL
(
  SELECT 'All others' as name, SUM(subtotal) as recovery
  FROM 
  (
    SELECT SUM(POTENTIAL_RECOVERY)
    FROM COMPLETE
    GROUP BY VENDOR_fullname
    ORDER BY SUM(POTENTIAL_RECOVERY) DESC
    LIMIT 10, 18446744073709551615
  ) as subtotal;
)