I have the following table:
+-----+------+
| qwe | asdd |
+-----+------+
| a | 3 |
| a | 4 |
| b | 5 |
| b | 6 |
+-----+------+
The result should be something like this:
+-----+------+
| qwe | asdd |
+-----+------+
| a | 12 |
| b | 30 |
+-----+------+
I wrote a code that may be only applied to the actual table, but if we add a row or more, it is not working well:
select qwe, (SUM(asd) - MIN(asd)) * MIN(asd) a from t
group by qwe
How would you recommend me to modify this code to make it work properly with tables like this?
+-----+------+
| qwe | asdd |
+-----+------+
| a | 3 |
| b | 4 |
| b | 5 |
| a | 6 |
| a | 7 |
+-----+------+
And get table like this:
+-----+------+
| qwe | asdd |
+-----+------+
| a | 12 |
| b | 126 |
+-----+------+