我很难用这个 where 子句得到正确的结果。我知道这是一个括号问题。有什么建议么?
WHERE a.EVENT_DATE Between &trend_dt And &enddate
AND a.INDICATOR Not In ('INQUIRY (NOS)','PCC')
And a.INDICATOR2 Not In ('CAT-NA','INQUIRY (NOS)')
And d.ACTIVE In ('C','F')
And d.ARCHIVE_STATUS in ('N','Y')
Or (d.ARCHIVE_STATUS Is Null)
谢谢!
结果的问题在于,Indicator 2 字段有时是空白的,它只返回 Indictator 2 字段中有内容的记录。
这是查询:
PROC SQL;
CREATE TABLE COMPLAINT_DATA_0 as
SELECT
a.EVENT_DATE,
a.INDICATOR,
a.INDICATOR2,
a.COMMITTEE_ACTION AS REVIEW_TYPE,
a.LEVEL_OF_EXCEPTION AS METHOD_RECD,
a.REFER_TO AS PLAN_NTWK,
b.DESCRIPTION AS SubCategory,
d.CROSSREF2 AS ConProvID,
d.LAST_NAME AS Provider,
a.MED_REC_NO AS MbrID,
a.CONFIRMED_BY AS IndProvID,
a.CODE_15 AS Severity,
MAX(c.INQUIRY_BODY) AS MaxProcStep,
e.Notes,
e.Notes2,
FROM VIPDBA.QA_PEER AS a LEFT JOIN VIPDBA.SYS_LOOKUPS AS b
ON a.INDICATOR2=b.CODE
LEFT JOIN VIPDBA.QA_PEER_INQUIRY AS c
ON a.LOOKUP_KEY=c.LOOKUP_KEY AND
a.MED_REC_NO=c.MED_REC_NO
LEFT JOIN VIPDBA.MASTER_CRED AS d
ON a.LOOKUP_KEY=d.LOOKUP_KEY
LEFT JOIN Complaint_Notes AS e
ON a.LOOKUP_KEY=e.LOOKUP_KEY AND
a.MED_REC_NO=e.MbrID
WHERE a.EVENT_DATE Between &trend_dt And &enddate
AND a.INDICATOR Not In ('INQUIRY (NOS)','PCC')
And a.INDICATOR2 Not In ('CAT-NA','INQUIRY (NOS)')
And d.ACTIVE In ('C','F')
And
( d.ARCHIVE_STATUS IN ('N','Y')
OR d.ARCHIVE_STATUS is null)
GROUP a.EVENT_DATE,
a.INDICATOR,
a.INDICATOR2,
b.DESCRIPTION,
d.CROSSREF2,
d.LAST_NAME,
a.MED_REC_NO,
a.CONFIRMED_BY,
a.CODE_15,
e.Notes,
e.Notes2,
d.archive_status,
d.active
ORDER BY
a.EVENT_DATE,
a.INDICATOR2,
b.DESCRIPTION,
d.CROSSREF2,
d.LAST_NAME
; 跑;