使用此查询:
SELECT
linerbltbl.billofladingid,
linerbltbl.grossweighttotal,
linerbltbl.netweighttotal,
linerblwisecontainerdetailstbl.containertype,
linerblwisecontainerdetailstbl.containernumber,
linerblwisecontainerdetailstbl.sealnumber,
linerblwisecontainerdetailstbl.principlecharge
FROM linerbltbl,
linerblwisecontainerdetailstbl
WHERE linerbltbl.shippername IS NOT NULL
AND linerbltbl.billofladingid =
linerblwisecontainerdetailstbl.billofladingid
请参阅this图片。它显示了我的输出 IS 以及我希望它是什么。
您将注意到重复的数据已被消除。有没有办法在我的查询中执行此操作?
答案 0 :(得分:0)
首先,我认为你错了。虽然您可以在查询本身内执行此操作(请参阅this页面),但最好不要在使用输出中执行此操作。例如,如果您正在获取此数据并将其粘贴到MS Excel中,则可以通过条件格式查看this帖子。如果你是从内部代码中使用它,你可以添加逻辑来处理它(因为我不知道你将用它做什么,所以很难添加任何例子。)
但是,如果你坚持从SQL中做这件事就会产生这种效果(借用链接的例子):
;with t as
(SELECT
linerbltbl.billofladingid,
linerbltbl.grossweighttotal,
linerbltbl.netweighttotal,
linerblwisecontainerdetailstbl.containertype,
linerblwisecontainerdetailstbl.containernumber,
linerblwisecontainerdetailstbl.sealnumber,
linerblwisecontainerdetailstbl.principlecharge
FROM linerbltbl,
linerblwisecontainerdetailstbl
WHERE linerbltbl.shippername IS NOT NULL
AND linerbltbl.billofladingid =
linerblwisecontainerdetailstbl.billofladingid
)
SELECT
CASE WHEN RR = 1 THEN billofladingid ELSE '' END BillOfLadingID,
CASE WHEN RR = 1 THEN grossweighttotal ELSE '' END GrossWeight,
CASE WHEN RR = 1 THEN netweighttotal ELSE '' END NetWeight,
containertype,
containernumber,
sealnumber,
principlecharge
FROM
(SELECT (ROW_NUMBER() OVER(PARTITION BY billofladingid ORDER BY billofladingid, grossweighttotal)) [RR], *
FROM t) SUBQUERY1