I have a table like this
How can i add new column with the value of column is the total value of price column with the same no_btsc like this
i use SUM but its no use. what SQL script i can use with case like this??
i use sum in nested query like this
Select id, name, price, no_btsc, (select SUM(price) from table1 group by no_btsc)
from table 1
3
Answers
You can try it by doing this:
you can solve this using windows function but you not need to use partition by because you need sum of all the values present in the column
if you are looking sum with respective to some values (kind of groups) then you can use partition by in the query
Another way of doing it is by using cross join to add a value to each row like this:
SELECT [id], [price], [Name], [btsc_no], [t2].[sum] FROM t1 CROSS APPLY (SELECT SUM([PRICE]) as sum FROM @Table) AS t2