下面的查询为我提供了我需要的所有信息。但是,由于修订级别,我得到了多个结果。大多数结果的第一个也是唯一一个修订返回一个空白。如果报价已被修订,则分配给修订 A。如果再次修订,则得到 B。我得到空白、A、B 等的结果。我想将查询限制为仅查看最大值如果它不是空白的。
SELECT
RTRIM(CUST_REF_NUMBER) AS "PICKUP #"
,RTRIM(SN.NUMBER) AS "NUMBER"
,DATE(PICKUP_TSTAMP) AS "PICKUP DATE"
,B.DUE_DATE
,WEIGHT
,TOTAL_PIECES AS "PIECES"
,V.QUOTE_ID AS "QUOTE"
,EQUIP AS "ACTUAL QUOTE PRICE"
,TOTAL_CHG AS "CHARGES"
,B.CUST AS "ACCOUNT NUMBER"
,C.ACCT_SPELLING AS "ACCOUNT NAME"
,H.REVISION
FROM AF.NOTIF SN
INNER JOIN AF.BILL B
ON SN.NUMBER = B.NUMBER
AND B.ARCHIVE_KEY = ''
AND B.CORRECTED = ''
AND B.TSTAMP >= SN.TSTAMP - 10 DAYS
INNER JOIN AF.PROS V
ON SN.NUMBER = V.NUMBER
INNER JOIN AF.CHARGES H
ON V.QUOTE_ID = H.QUOTE_ID
AND H.STATUS = 'X'
LEFT OUTER JOIN AF.SPELLING C
ON B.CUST = C.ACCT_NUM
AND C.TYPE = 'M'
WHERE WEB_ID IN ('XXXXXXX','XXXXXXX','XXXXXXX')
AND SN.TSTAMP > TIMESTAMP(CHAR(CURRENT DATE - 7 DAYS)||'-00.00.00.000000')
ORDER BY PICKUP_TSTAMP