答案 0 :(得分:1)
尝试将ROW_NUMBER()
与OVER(PARTITION BY)
一起使用
create table #temp (id int, patientname varchar(30), doc_id int, [order] int)
SELECT id, patientname, doc_id, [order] FROM (
SELECT id, patientname, ROW_NUMBER() OVER(PARTITION BY doc_id ORDER BY id)
R,
doc_id, [order]
FROM #temp
) B
ORDER BY R, doc_id