Anda dapat melakukan ini dengan menghitung baris dalam satu tahun. Kemudian perbarui semua kecuali yang pertama:
with toupdate as (
select t.*, row_number() over (partition by [year] order by [date]) as seqnum
from t
)
update toupdate
set [year] = NULL
where seqnum > 1;
Jika Anda menginginkan ini sebagai select
pernyataan:
with ts as (
select t.*, row_number() over (partition by [year] order by [date]) as seqnum
from t
)
select [date],
(case when seqnum = 1 then [year] end) as [year]
from ts;