假设表名为 Table1,字段为 (分组号,工序代码,顺序号),其中顺序号是指工序代码在当前分组中出现的先后顺序Select A.分组号, (Case when B.顺序 IS Not Null then '==>' else null end) as 箭头, A.工序代码From Table1 A Left Join (Select 分组号,Min(顺序号) 顺序 From Table1 Where 分组号 not in ( Select Min(分组号) from Table1 ) ) B On A.分组号=B.分组号 and A.顺序号=B.顺序Order by A.分组号,A.顺序号
呵呵,这么小的细节你也看出来了。Select A.分组号, (Case when B.顺序 IS Not Null then '==>' else null end) as 箭头, A.工序代码From Table1 A Left Join (Select 分组号,Min(顺序号) 顺序 From Table1 Where 分组号 not in ( Select Min(分组号) from Table1 ) group by 分组号 ) B On A.分组号=B.分组号 and A.顺序号=B.顺序Order by A.分组号,A.顺序号