select * from ( select row_number() over(partition by Gid order by Gid ASC) as RowN, * from( select b.Gid, a.OrderNo,b.Carcode from fit_CarOrder a inner join Fit_CarDetail b on a.OrderNo=b.DetailNo inner join Fit_OrderDetail c on a.Gid=c.OrderGid where a.orderno='201909180000038000099988' ) as bb) as tt where tt.RowN=1
分组排序对于主单对应多个明细 分组排序去重 如果 明细中对应到第三个明细中也存在对应的主单信息时 最好取决于第二个表的明细ID来排序分组筛选重复项