在DB2上选择Unique / Distinct字段?

时间:2015-12-07 13:46:45

标签: sql db2

大家好,我写了一个查询,假设要提取两个地点的邮政编码及其费率。 但是我每个托运人只需要一个拉链,但由于某种原因,它仍然会返回多个字段。

SELECT UNIQUE LEFT(T.ORIGPC,3) SHIP_ZIP,  LEFT(T.DESTPC,3) DEST_ZIP, BILL_NUMBER, T.ORIGCITY, T.ORIGPROV, 
T.DESTCITY, T.DESTPROV, A.RATE, T.DISTANCE
FROM TLORDER T, ACHARGE_TLORDER A
WHERE CREATED_TIME >= CURRENT TIMESTAMP - 1 MONTH
AND BILL_NUMBER <> '0'
AND DISTANCE <> '0'
AND RATE <> '0'
AND RATE NOT LIKE '-%'
AND DISTANCE NOT LIKE '-%'
AND ORIGPC <> ''
AND REQUESTED_CODE = 'FS_STD' 
AND A.DETAIL_LINE_ID = T.DETAIL_LINE_ID
AND DESTPC <> ''
AND BILL_NUMBER NOT LIKE 'Q%'
AND ACODE_ID = 'FS_STD'
AND RATE <= '2' 
ORDER BY LEFT(ORIGPC,3)

Hidden Bill Number for obvious reasons

预期结果 enter image description here

1 个答案:

答案 0 :(得分:0)

删除Bill_number和距离! 因此,只填充了唯一的邮政编码 谢谢你的时间人员