I have data like this:
Team | goal
a | 5
b | 8
a | 5
f | 8
c | 5
a | 3
g | 5
d | 8
a | 5
e | 4
a | 9
a | 8
b | 2
c | 3
f | 1
I want to make select table to be like this:
example:
Team | sum(goal)
a | 14
b | 13
c | 12
d | 11
others | sum(outside limit 0,4)
So I want to list top 4 team with his total goal
and also return all outside limit into one record named ‘others’ (sum the goal from other team outside top 4)
a,b,c,d is not defined yet, use select , order, and limit to get TOP 4 Goal
Two queries joined by a union will give the desired result: