/*
INSERT INTO TC79(PatientID,AdmissionDate,DischargeDate,Cost)
SELECT * FROM (
SELECT 709,TO_DATE(‘2011-07-27‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-07-31‘,‘YYYY-MM-DD‘),450 FROM DUAL
UNION ALL
SELECT 709,TO_DATE(‘2011-08-01‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-08-23‘,‘YYYY-MM-DD‘),2070 FROM DUAL UNION ALL
SELECT 709,TO_DATE(‘2011-08-31‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-08-31‘,‘YYYY-MM-DD‘),90 FROM DUAL UNION ALL
SELECT 709,TO_DATE(‘2011-09-01‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-09-14‘,‘YYYY-MM-DD‘),1260 FROM DUAL UNION ALL
SELECT 709,TO_DATE(‘2011-12-01‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-12-31‘,‘YYYY-MM-DD‘),2790 FROM DUAL UNION ALL
SELECT 1624,TO_DATE(‘2011-06-07‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-06-28‘,‘YYYY-MM-DD‘),1980 FROM DUAL UNION ALL
SELECT 1624,TO_DATE(‘2011-06-29‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-07-31‘,‘YYYY-MM-DD‘),2970 FROM DUAL UNION ALL
SELECT 1624,TO_DATE(‘2011-08-01‘,‘YYYY-MM-DD‘),TO_DATE(‘2011-08-02‘,‘YYYY-MM-DD‘),180 FROM DUAL
)
*/
WITH CTE AS(
SELECT T.*, LEAD(ADMISSIONDATE,1) OVER(PARTITION BY PATIENTID ORDER BY ADMISSIONDATE) AS NEXTADMISSIONDATE,
CASE WHEN LEAD(ADMISSIONDATE,1) OVER(PARTITION BY PATIENTID ORDER BY ADMISSIONDATE)=T.DISCHARGEDATE+1 THEN 1
ELSE 0 END AS ISCONT
FROM TC79 T)
SELECT A.*
, CASE WHEN A.ISCONT =1 THEN
( SELECT MIN(DISCHARGEDATE) FROM CTE B WHERE B.ADMISSIONDATE>A.ADMISSIONDATE AND A.ISCONT<>B.ISCONT AND A.PATIENTID=B.PATIENTID)
ELSE A.DISCHARGEDATE END AS DISCHARGEDATE
FROM CTE A
TC79
时间: 2024-12-26 14:18:40
TC79的相关文章
win7 64位 TortoiseSVN-1.8.4客户端安装
下载地址链接:http://pan.baidu.com/s/1nukeBVz 密码:tc79 (32 64位都有,注意区分) next一路安装 安装好后,在需要和服务器同步的文件夹图标上--鼠标右键--TortoiseSVN--Create repository here--如果之前这个文件上使用过SVN,则只用输入用户名,密码即可 参考资料 http://www.cnblogs.com/fyhui/p/3591381.html