亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

多個查詢同一表但列不同

多個查詢同一表但列不同

慕雪6442864 2019-07-11 12:42:11
多個查詢同一表但列不同我試圖從兩個不同的表中得到更多的匯總結果的列SET @start_res = 20150301;SET @finish_res= 20150501;SET @finish_check= 20150801;SET @start_check= 20150301;SET @daily_hos= 3;SELECT* from    ( 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 group by DAY_IN  )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 group by DAY_IN ) 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 group by DAY_IN  )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 group by DAY_IN   )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 group by DAY_IN  )d當然,它不能工作,只有第一個顯示的列(Arr)工作,而其他列顯示一個錯誤的輸出。我哪里錯了?
查看完整描述

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


查看完整回答
反對 回復 2019-07-11
?
交互式愛情

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有疑問。您可能需要使用有關另一個表的信息更新您的問題。


查看完整回答
反對 回復 2019-07-11
  • 3 回答
  • 0 關注
  • 574 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號