I am new to SQL and not getting even simple things. I am wondering if the following code does not add a real column?
select *
sum(value) over (partition by prename order by NumberOfDays) SumValue
from (select *, row_number() over (order by NumberOfDays) rn from
tablenames) as t
order by rn
I thought with this code I would create a new column called SumValue. When I execute the code above it works fine and the column SumValue with all its values is shown but when I try to calcualte with this column, let's say:
ALTER TABLE tablenames
ADD AvValue float;
UPDATE [DatabaseXY].[dbo].[tablenames]
SET AvH = [SumValue]/[NumberOfDays]
SSMS tells me that SumValue is an invalid column name. Why is that? Even if I refresh or restart SSMS and look into the object explorer there is no column called SumValue.. I guess with my presented code I only create kinda temporary columns but how do I add those values to a real column?
Thank you so much!