Jumat, 17 April 2020
UPDATE NOMOR ROWNUMBER()
declare @coba table (nomer int,id_unik int,id_group int, jual money)
insert into @coba
values (null,2,3,100),(null, 3,3,100),(null,4,3,100), (null,5,5,200),(null,6,5,200)
-------------------------
select row_number() over ( partition by id_group order by id_group),* from @coba
(No column name) nomer id_unik id_group jual
1 NULL 2 3 100.0000
2 NULL 3 3 100.0000
3 NULL 4 3 100.0000
1 NULL 5 5 200.0000
2 NULL 6 5 200.0000
-----------------------------
UPDATE T
SET T.nomer = TT.ROW_ID
--select *
FROM @coba AS T
INNER JOIN (SELECT ROW_NUMBER() OVER ( partition by id_group order by id_group ) AS ROW_ID, id_unik
FROM @coba ) AS TT
ON T.id_unik = TT.id_unik
select row_number() over ( partition by id_group order by id_group),* from @coba
(No column name) nomer id_unik id_group jual
1 1 2 3 100.0000
2 2 3 3 100.0000
3 3 4 3 100.0000
1 1 5 5 200.0000
2 2 6 5 200.0000
-------------------------------------
update @coba set jual=0 where nomer>1
select row_number() over ( partition by id_unik order by id_unik),* from @coba
1 1 2 3 100.0000
1 2 3 3 0.0000
1 3 4 3 0.0000
1 1 5 5 200.0000
1 2 6 5 0.0000
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar