我正在尝试获取更多的列来汇总来自两个不同表的结果
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)起作用,而其他列显示错误的输出。
我错在哪里?
4条答案
按热度按时间q0qdq0h21#
尝试this:-
您的问题提到要连接两个表,但似乎只有
t_hospital
有问题。您可能想用另一个表的信息更新您的问题。i7uq4tfw2#
如果我没听错的话,这就是你想要的。
lfapxunr3#
这是一个非常常见的模式:
ylamdve64#
在SQLServer2005+中,可以使用窗口函数。但是mysql不支持它。
在子查询中,select语句必须具有join运算符。这样地: