0

嘿伙计们,我对这个有点难过。这是声明。我正在寻找在过去 6 个月内进行过 3 次以上就诊的患者。我虽然这会给我更容易的遮阳篷。

SELECT od_ar_demographics.PATIENT_ARPTYPE, 
       od_ar_demographics.PATIENT_NAME, 
       od_ar_demographics.MR_NUMBER, 
       OD_IP1.IP1ADMIT_DATE, 
       OD_IP1.IP1DISC_DATE, 
       od_ar_demographics.PATIENT_TYPE
FROM            od_ar_demographics INNER JOIN
                         OD_IP1 ON od_ar_demographics.PATIENT_NUMBER = OD_IP1.IP0NUMBER
where         Mr_number in (select MR_number from (SELECT MR_number, 
 COUNT(MR_number) as LLL
FROM  od_ar_demographics INNER JOIN
                         OD_IP1 ON od_ar_demographics.PATIENT_NUMBER = OD_IP1.IP0NUMBER WHERE  IP1admit_date >(getdate()- 180 ) GROUP BY MR_number
HAVING ( COUNT(MR_number) > 3 ))
4

1 回答 1

0

试试这个,你的子查询需要别名

SELECT od_ar_demographics.PATIENT_ARPTYPE, 
       od_ar_demographics.PATIENT_NAME, 
       od_ar_demographics.MR_NUMBER, 
       OD_IP1.IP1ADMIT_DATE, 
       OD_IP1.IP1DISC_DATE, 
       od_ar_demographics.PATIENT_TYPE
FROM  od_ar_demographics 
INNER JOIN OD_IP1 
    ON od_ar_demographics.PATIENT_NUMBER = OD_IP1.IP0NUMBER
WHERE Mr_number IN (SELECT MR_number 
                    FROM (  
                            SELECT MR_number, COUNT(MR_number) as LLL
                            FROM  od_ar_demographics 
                            INNER JOIN OD_IP1 
                            ON od_ar_demographics.PATIENT_NUMBER = OD_IP1.IP0NUMBER 
                            WHERE  IP1admit_date > getdate()- 180
                            GROUP BY MR_number
                            HAVING COUNT(MR_number) > 3 
                          ) A
                    )
于 2013-01-15T21:21:25.600 回答