ZJYCMBSFJL视图的sql语句,慢病系统

SELECT
    `p`.`id` AS `id`,
    `p`.`name` AS `name`,
    `p`.`gender` AS `gender`,
    `p`.`diseaseType` AS `diseaseType`,
    `p`.`dataBirth` AS `dataBirth`,
    `p`.`bloodType` AS `bloodType`,
    `p`.`dutyUserUuid` AS `dutyUserUuid`,
    `p`.`deathStatus` AS `deathStatus`,
    `a`.`tnbid` AS `tnbid`,
    `a`.`tnbhzid` AS `tnbhzid`,
    `a`.`TNBVisitDate` AS `TNBVisitDate`,
    `a`.`TNBNextDate` AS `TNBNextDate`,
    `a`.`INPUT_USER_ID` AS `TNB_INPUT_USER_ID`,
    `b`.`jsbid` AS `jsbid`,
    `b`.`jsbhzid` AS `jsbhzid`,
    `b`.`JSBVisitDate` AS `JSBVisitDate`,
    `b`.`JSBNextDate` AS `JSBNextDate`,
    `b`.`INPUT_USER_ID` AS `JSB_INPUT_USER_ID`,
    `c`.`gxyid` AS `gxyid`,
    `c`.`gxyhzid` AS `gxyhzid`,
    `c`.`GXYVisitDate` AS `GXYVisitDate`,
    `c`.`GXYNextDate` AS `GXYNextDate`,
    `c`.`INPUT_USER_ID` AS `GXY_INPUT_USER_ID`,
    `d`.`fjh1id` AS `fjh1id`,
    `d`.`fjhhzid` AS `fjhhzid`,
    `d`.`FJHVisitDate` AS `FJHVisitDate`,
    `d`.`FJHNextDate` AS `FJHNextDate`,
    `d`.`INPUT_USER_ID` AS `FJH_INPUT_USER_ID`,
    `e`.`fjh2id` AS `fjh2id`,
    `e`.`fjh2hzid` AS `fjh2hzid`,
    `e`.`FJH2VisitDate` AS `FJH2VisitDate`,
    `e`.`FJH2NextDate` AS `FJH2NextDate`,
    `e`.`INPUT_USER_ID` AS `FJH2_INPUT_USER_ID` 
FROM
    (
    (
    (
    (
    (
    `PatientInfo` `p`
    LEFT JOIN (
SELECT
    `HEALTH_DIABETES_FOLLOW`.`ID` AS `tnbid`,
    `HEALTH_DIABETES_FOLLOW`.`patientId` AS `tnbhzid`,
    `HEALTH_DIABETES_FOLLOW`.`VISIT_DATE` AS `TNBVisitDate`,
    `HEALTH_DIABETES_FOLLOW`.`NEXT_DATE` AS `TNBNextDate`,
    `HEALTH_DIABETES_FOLLOW`.`INPUT_USER_ID` AS `INPUT_USER_ID` 
FROM
    `HEALTH_DIABETES_FOLLOW` 
WHERE
    ( `HEALTH_DIABETES_FOLLOW`.`patientId`, `HEALTH_DIABETES_FOLLOW`.`VISIT_DATE` ) IN (
SELECT
    `HEALTH_DIABETES_FOLLOW`.`patientId`,
    max(`HEALTH_DIABETES_FOLLOW`.`VISIT_DATE` ) 
FROM
    `HEALTH_DIABETES_FOLLOW` 
GROUP BY
    `HEALTH_DIABETES_FOLLOW`.`patientId` 
    ) 
    ) `a` ON ( `p`.`id` = `a`.`tnbhzid` ) 
    )
    LEFT JOIN (
SELECT
    `HEALTH_MENTAL_DISEASE`.`ID` AS `jsbid`,
    `HEALTH_MENTAL_DISEASE`.`patientId` AS `jsbhzid`,
    `HEALTH_MENTAL_DISEASE`.`VISIT_DATE` AS `JSBVisitDate`,
    `HEALTH_MENTAL_DISEASE`.`NEXT_DATE` AS `JSBNextDate`,
    `HEALTH_MENTAL_DISEASE`.`INPUT_USER_ID` AS `INPUT_USER_ID` 
FROM
    `HEALTH_MENTAL_DISEASE` 
WHERE
    (`HEALTH_MENTAL_DISEASE`.`patientId`,`HEALTH_MENTAL_DISEASE`.`VISIT_DATE` ) IN (
SELECT
    `HEALTH_MENTAL_DISEASE`.`patientId`,
    max(`HEALTH_MENTAL_DISEASE`.`VISIT_DATE` ) 
FROM
    `HEALTH_MENTAL_DISEASE` 
GROUP BY
    `HEALTH_MENTAL_DISEASE`.`patientId` 
    ) 
    ) `b` ON ( `p`.`id` = `b`.`jsbhzid` ) 
    )
    LEFT JOIN (
SELECT
    `HEALTH_HYPER_PATI_SERVICE_NEW`.`ID` AS `gxyid`,
    `HEALTH_HYPER_PATI_SERVICE_NEW`.`patientId` AS `gxyhzid`,
    `HEALTH_HYPER_PATI_SERVICE_NEW`.`VISIT_DATE` AS `GXYVisitDate`,
    `HEALTH_HYPER_PATI_SERVICE_NEW`.`NEXT_DATE` AS `GXYNextDate`,
    `HEALTH_HYPER_PATI_SERVICE_NEW`.`INPUT_USER_ID` AS `INPUT_USER_ID` 
FROM
    `HEALTH_HYPER_PATI_SERVICE_NEW` 
WHERE
    (`HEALTH_HYPER_PATI_SERVICE_NEW`.`patientId`, `HEALTH_HYPER_PATI_SERVICE_NEW`.`VISIT_DATE` ) IN (
SELECT
     `HEALTH_HYPER_PATI_SERVICE_NEW`.`patientId`,
    max( `HEALTH_HYPER_PATI_SERVICE_NEW`.`VISIT_DATE` ) 
FROM
    `HEALTH_HYPER_PATI_SERVICE_NEW` 
GROUP BY
    `HEALTH_HYPER_PATI_SERVICE_NEW`.`patientId` 
    ) 
    ) `c` ON ( `p`.`id` = `c`.`gxyhzid` ) 
    )
    LEFT JOIN (
SELECT
    `HEALTH_TUBERCULOSIS_VISIT`.`ID` AS `fjh1id`,
    `HEALTH_TUBERCULOSIS_VISIT`.`patientId` AS `fjhhzid`,
    `HEALTH_TUBERCULOSIS_VISIT`.`VISIT_DATE` AS `FJHVisitDate`,
    `HEALTH_TUBERCULOSIS_VISIT`.`NEXT_DATE` AS `FJHNextDate`,
    `HEALTH_TUBERCULOSIS_VISIT`.`INPUT_USER_ID` AS `INPUT_USER_ID` 
FROM
    `HEALTH_TUBERCULOSIS_VISIT` 
WHERE
    ( `HEALTH_TUBERCULOSIS_VISIT`.`patientId`, `HEALTH_TUBERCULOSIS_VISIT`.`VISIT_DATE` ) IN (
SELECT
    `HEALTH_TUBERCULOSIS_VISIT`.`patientId`,
    max(`HEALTH_TUBERCULOSIS_VISIT`.`VISIT_DATE` ) 
FROM
    `HEALTH_TUBERCULOSIS_VISIT` 
GROUP BY
    `HEALTH_TUBERCULOSIS_VISIT`.`patientId` 
    ) 
    ) `d` ON ( `p`.`id` = `d`.`fjhhzid` ) 
    )
    LEFT JOIN (
SELECT
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`ID` AS `fjh2id`,
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`patientId` AS `fjh2hzid`,
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`VISIT_DATE` AS `FJH2VisitDate`,
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`NEXT_DATE` AS `FJH2NextDate`,
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`INPUT_USER_ID` AS `INPUT_USER_ID` 
FROM
    `HEALTH_TUBERCULOSIS_VISIT_MORE` 
WHERE
    ( `HEALTH_TUBERCULOSIS_VISIT_MORE`.`patientId`,`HEALTH_TUBERCULOSIS_VISIT_MORE`.`VISIT_DATE` ) IN (
SELECT
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`patientId`,
    max(`HEALTH_TUBERCULOSIS_VISIT_MORE`.`VISIT_DATE` ) 
FROM
    `HEALTH_TUBERCULOSIS_VISIT_MORE` 
GROUP BY
    `HEALTH_TUBERCULOSIS_VISIT_MORE`.`patientId` 
    ) 
    ) `e` ON ( `p`.`id` = `e`.`fjh2hzid` ) 
    ) 
WHERE
    `p`.`deathStatus` = 0

你可能感兴趣的:(sql,数据库,mysql)