ID|FK|cost|name |
--|--|----|------
1 | 1| 200| name2|
2 | 1| 100| name2|
3 | 3| 900| name1|
4 | 2| 500| name3|
5 | 2| 100| name3|
6 | 2| 200| name3|
i need this result Where
ID|FK|cost-|name |
--|--|-----|------
1 | 1| 300 | name2|
2 | 3| 900 | name1|
3 | 2| 800 | name3|
The following SQL should work to get the desired output
SELECT id, fk, SUM(cost) AS cost, name FROM <table> GROUP BY name ORDER BY id;
Going forward, please read the SO guidelines and help center to understand the purpose of this forum.