我写了这段代码
SELECT
cast(isnull(x.hc,'') AS VARCHAR(500)) as A,
Case
When cast(isnull(p.dg,'') AS VARCHAR(500)) = '0' then ''
else cast(isnull(p.dg,'') AS VARCHAR(500))
End as B,
Case
When cast(isnull(h.cno,'') as varchar(500)) = '0' then ''
else cast(isnull(h.cno,'') as varchar(500))
End as C, --added
cast(isnull(p.vol,0) as varchar(500)) as D,
cast(isnull(p.weigh,0) as varchar(500)) as E
FROM ship g
inner join S_M d on d.ship_id = g.ship_id
left join Pack h on h.ship_id = g.ship_id
left join pack_d p on p.pack_id = h.pack_id
left join comm x on x.comm_id = p.comm_id
WHERE g.ship_pk = @ship_pk
GROUP BY cast(isnull(x.hc,'') AS VARCHAR(500)), cast(isnull(p.dg,'') AS VARCHAR(500)), cast(isnull(h.cno,'') as varchar(500)), cast(isnull(p.vol,0) as varchar(500)), cast(isnull(p.weigh,0) as varchar(500))
这给了我输出
A B C D E
123 Yes AB456 26.34 28.45
123 Yes AB687 26.34 28.45
125 No AB794 22.58 24.36
125 No AB456 22.58 24.36
125 No AB687 22.58 24.36
如何更改上面的代码,以便我可以得到输出
A B C D E
123 Yes AB456 26.34 28.45
AB687 26.34 28.45
125 No AB794 22.58 24.36
AB456 22.58 24.36
AB687 22.58 24.36
如何从表格的前两列中删除重复值如上所示?我不会在这里删除任何行,而只是删除重复的值并将该字段保留为空白。
我怎样才能做到这一点?