我有以下数据集
Create table #table(
Message varchar(10),
ID varchar(5),
ParentID varchar(5))
Insert into #table
select 'Parent','123',''
UNION
select 'Child','234','123'
UNION
select 'Child','345','123'
UNION
select 'Child','145','123'
UNION
select 'Parent','333',''
UNION
select 'Child','567','333'
UNION
select 'Child','789','333'
UNION
select 'Child','100','333'
UNION
select 'Child','111','333'
select * from #table
当我选择数据时,数据看起来是随机的。但我想按以下顺序
Message ID ParentID
Parent 123
Child 234 123
Child 345 123
Child 145 123
Parent 333
Child 567 333
Child 789 333
Child 100 333
Child 111 333
我尝试使用 row number ,它不适用于以下序列。有人可以帮帮我吗 ?