我是SQL的新手,尤其是Oracle。我需要通过连接字段“UNIQUE_PROVIDER_PATIENT_COMBO”进行计数,并且仅包括那些具有> = 2的记录 - 换句话说,仅显示相同提供者/患者组合存在多次的那些记录。我很亲密,但不能一路走到那里。我已经尝试过使用公共表表达式,并且没有完成最后一步。基本查询如下。非常感谢帮助!
SELECT DISTINCT
pat.PAT_NAME "PATIENT"
,pat.PAT_ID
,prov.PROV_NAME "VISIT PROVIDER"
,prov.PROV_ID
,enc.CONTACT_DATE "VISIT DATE"
,prov.PROV_NAME || ' ' || '+' || ' ' || pat.PAT_NAME AS "PROVIDER + PATIENT"
,prov.PROV_ID || ' ' || '+' || ' ' || pat.PAT_ID AS "UNIQUE_PROVIDER_PATIENT_COMBO"
FROM
CMRCL_TFH.PATIENT pat
INNER JOIN CMRCL_TFH.PAT_ENC enc ON pat.PAT_ID = enc.PAT_ID
INNER JOIN CMRCL_TFH.CLARITY_DEP dep ON enc.DEPARTMENT_ID = dep.DEPARTMENT_ID
INNER JOIN CLARITY_SER prov ON enc.VISIT_PROV_ID = prov.PROV_ID
WHERE
enc.CONTACT_DATE BETWEEN '01-JAN-18' AND '31-MAR-18'
GROUP BY
pat.PAT_NAME
, pat.PAT_ID
, prov.PROV_NAME
, prov.PROV_ID
, enc.CONTACT_DATE
, prov.PROV_NAME || ' ' || '+' || ' ' || pat.PAT_NAME
, prov.PROV_ID || ' ' || '+' || ' ' || pat.PAT_ID
ORDER BY "PROVIDER + PATIENT";