3 回答
TA贡献1801条经验 获得超8个赞
SELECT DAY_IN, COUNT(*) AS arr, SUM(IF(PAT_STATUS like '%ong%', 1, 0)) AS ONG1, SUM(IF(PAT_STATUS like '%rtde%', 1, 0)) AS RTED, SUM(IF(PAT_STATUS like '%pol%', 1, 0)) AS POL1, SUM(IF(PAT_STATUS like '%para%', 1, 0)) AS paraFROM t_hospital WHERE DAY_IN between @start_check and @finish_check and RES_DATE between @start_res and @finish_res and ID_daily_hos =@daily_hosGROUP BY DAY_IN
TA贡献1712条经验 获得超3个赞
试试这个:-
SET @start_res = 20150301;
SET @finish_res= 20150501;
SET @finish_check= 20150801;
SET @start_check= 20150301;
SET @daily_hos= 3;
SELECT
(SELECT COUNT(DAY_IN) AS arr FROM t_hospital WHERE
DAY_IN between @start_check and @finish_check and
RES_DATE between @start_res and @finish_res and
ID_daily_hos =@daily_hos) e,
(SELECT COUNT(PAT_STATUS) AS ONG1 FROM t_hospital WHERE
PAT_STATUS like '%ong%' and
DAY_IN between @start_check and @finish_check and
RES_DATE between @start_res and @finish_res and
ID_daily_hos =@daily_hos) a,
(SELECT COUNT(PAT_STATUS) AS RTED FROM t_hospital WHERE
PAT_STATUS like '%rtde%' and
DAY_IN between @start_check and @finish_check and
RES_DATE between @start_res and @finish_res and
ID_daily_hos =@daily_hos)b,
(SELECT COUNT(PAT_STATUS) AS POLI FROM t_hospital WHERE
PAT_STATUS like '%pol%' and
DAY_IN between @start_check and @finish_check and
RES_DATE between @start_res and @finish_res and
ID_daily_hos =@daily_hos) c,
(SELECT COUNT(PAT_STATUS) AS para FROM t_hospital WHERE
PAT_STATUS like '%para%' and
DAY_IN between @start_check and @finish_check and
RES_DATE between @start_res and @finish_res and
ID_daily_hos =@daily_hos) d
您的问题提到了连接两个表,但似乎只有t_hospital有疑问。您可能需要使用有关另一个表的信息更新您的问题。
添加回答
举报