3 回答

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個(gè)贊
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貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊
試試這個(gè):-
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
您的問(wèn)題提到了連接兩個(gè)表,但似乎只有t_hospital有疑問(wèn)。您可能需要使用有關(guān)另一個(gè)表的信息更新您的問(wèn)題。
添加回答
舉報(bào)