0

やあみんな、私はこれに少し困惑しています。これが声明です。過去6ヶ月間に3回以上来院された患者さんを探しています。私はこれが私に簡単なawserを与えるだろうと思った。

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 に答える