我正在尝试从2个不同的表格中总结出结果的更多列
meal_with_tax = tax(meal_cost)
当然它不起作用,只是第一个显示的列(arr)有效,而其他列显示错误的输出。
我哪里错了?
答案 0 :(得分:3)
这是一种非常常见的模式:
AppDelegate.swift
答案 1 :(得分:0)
在SQL Server 2005+中,您可以使用Window函数。 但MySQL不支持它。
在Subquery中,select语句必须具有join运算符。像这样:
SELECT * FROM (
(SELECT COUNT(..) ...) AS C1
INNER JOIN (SELECT COUNT(...) ...) AS C2
ON <condition>
INNER JOIN ... )
答案 2 :(得分:0)
试试这个: -
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
您的问题提及加入2个表格,但似乎只有t_hospital
有问题。您可能希望使用有关另一个表的信息更新您的问题。
答案 3 :(得分:0)
如果我理解正确,这就是你想要的。
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) 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) AS 'arr' ,
(SELECT COUNT(PAT_STATUS) 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) AS 'ONG1' ,
(SELECT COUNT(PAT_STATUS) 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) AS 'RTED' ,
(SELECT COUNT(PAT_STATUS) 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) AS 'POLI' ,
(SELECT COUNT(PAT_STATUS) 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) AS 'para'