I have a sql query which returns a sum of total amount by user and I am trying to add another column which uses the total and multiply it by a number

This returns a total amount by user

SELECT id,name,sum(amount) as total_amount
 from Contribution
GROUP by name

Now I need to add another column which uses the total amount by user and multiply it by 5 and then divide it by 100 and then add the results to the total amount.

Something like this

SELECT id,name,sum(amount) as total_amount,(sum(amount) * 5)/100 + (sum(amount)) as investment from Contribution
GROUP by name

I got it to work.

SELECT id,name,sum(amount) as total_amount, ((sum(amount)*5)/100)+sum(amount) as investement from Contribution
GROUP by name

Are really using SQL Server ?

Your query would not work. You have included id in the select clause without aggregate but not in GROUP BY

It would have to be MySQL or MariaDB for that math to work.

I'm just curious and I might be missing it but where did the OP say that they were using SQL Server? They said the "have a sql query" but that doesn't mean SQL Server.

It is me. I just assumed it is SQL Server as SQLTeam is only for SQL Server many many years ago.

Got it and understood. Thank you for the response!