Knowledge management feedback System, analysis of Knowledge Retrieval office (Beijing Shanghai Tianjin Hong Kong New York Tokyo .... Suzhou) source, I need to find out which offices are more frequently, drain the top 5, and calculate the sum of the number of queries for all remaining departments.
The database is MySQL.
1 Spell out the top five
Select sum (countas fromgroupby5;
2. Retrieve all other
Theoretically it should be:
Select ' other ',sum(countfromwhere not in (select from Group by 5);
However, SQL cannot execute, prompting:
This version of MySQL doesn ' t yet support ' LIMIT & in/all/any/some subquery
You cannot use limit in a subquery, the solution is to set a layer of queries here and spell it out:
Select ' other ',sum(countfromwhere not in (select from (Selectfromgroupby5 as T);
Succeed in getting results ~
The sum of the first five data and all other data of SQL query