top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

SQL: Get the highest number of each group and combine the result per parent column?

+1 vote
226 views
id  |  group  |  parent  |  value
1       123        1         10
2       123        1         25
3       224        1         12
4       224        1         22
5       225        2         18
6       225        2         10
7       326        2         18
8       326        2         35

Now I need to grab the highest number of each group and combine the result per parent column so the wanted result would be like the following:

group  |  parent  |   value
123         1          47
225         2          53
posted Jun 16, 2015 by Shivaranjini

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

use a nested query like this:

select parent, sum(max_of_group_value) from ( select parent, group max(value) as max_of_group_value) from <table> group by parent, group ) t group by parent; 
answer Jun 17, 2015 by Manikandan J
...