with Rtbl_nhatky_khohoiam
as
(
select *
, row_number() over(partition by makien order by makien) as rnk
from tbl_nhatky_khohoiam
)
update Rtbl_nhatky_khohoiam
set stt = rnk
go
SELECT makien, madh_hb, macummay, [1],[2],[3] FROM (select makien,macummay, madh_hb,stt,w from tbl_nhatky_khohoiam) as source PIVOT (sum(w)FOR stt IN ([1],[2],[3])) as PVT where madh_hb='G4300.DOT06-07.16'