Reputation: 166
I'm not sure what should I write in the following SQL query to show the following result:
Data:
Color is unique column...
Result:
Upvotes: 0
Views: 114
Reputation: 204924
select color as [name/color], value
from your_table
union all
select name, sum(value)
from your_table
group by name
And if you need a specific order then you can do
select [name/color], value
from
(
select color as [name/color], value, name as order_column
from your_table
union all
select name, sum(value), name
from your_table
group by name
) x
order by order_column
Upvotes: 6