I have a table like this
----------------------
code sales goal
----------------------
b 7 20
b 12 20
a 9 15
c 4 3
a 4 15
And I want to perform an agg function to group by a sum only on 'sales' column, because 'goal' column is common to a given value in 'code' column to get something more like this
---------------------------------
code total goal
---------------------------------
b 19 20
a 13 15
c 4 3
Is there a way to perform something like this?
SELECT code, SUM(sales) AS total, goal FROM such_table GROUP BY code
To then operate the columns to achieve the following future operations:
------------------------------------------------------
code sum(sales) intact(goal) achvd(100*sum/goal)
------------------------------------------------------
b 19 20 95
a 13 15 86.6
c 4 3 133.3