Is it possible to build a SQL query to output only n number of rows and sum up the rest of the columns returned n+1 th row.
for instance, I have two columns returned from an sql query. First column is the Name and the second column contains the count values. The names are distinct and the counts are numbers.
The query should only return 3 rows and if there are more than 3 rows, they all should be summed up to a fourth row with the name as 'Others' and the counts of the rest of the rows summed up into the fourth row.
Kindly help me out. Thanks in advance.
(example)
Table
Name | Value
First - 12
Second - 11
Third - 9
Fourth - 15
Fifth - 13
Sixth - 8
Query result
Name | Value
First - 12
Second - 11
Third - 9
Others - 36