我目前有 1 个表和 2 个嵌套选择,我想将两个嵌套选择联合在一起,我希望结果集显示两个不同的列,每个结果集一个(每个嵌套选择一个列)。IE 三列共 t_stamp, R02AO11, R03AO11。这几天我一直在努力解决这个问题,任何可以帮助我的人都将不胜感激。我发现这个例子 使用 SELECT UNION 并从一个表中返回两列的输出,这对我来说没有意义——也许有点过头了。希望它不是太多的重新发布。再次感谢。=)
Select t_stamp,
MIN(R02AO11)
FROM
(
SELECT
t_stamp,
R02AO11
FROM
tag_history
WHERE
from_unixtime(floor(unix_timestamp(t_stamp)/60)*60) BETWEEN '2012-11-01 00:00:00' AND '2012-11-30 23:59:59'
AND (R02AO11 IS NOT NULL AND R02AO11 > 0)
) AS min_tag_history
GROUP BY LEFT(t_stamp, 10)
UNION ## UNION ALL
Select t_stamp,
MIN(R03AO11)
FROM
(
SELECT
t_stamp,
R03AO11
FROM
tag_history
WHERE
from_unixtime(floor(unix_timestamp(t_stamp)/60)*60) BETWEEN '2012-11-01 00:00:00' AND '2012-11-30 23:59:59'
AND (R03AO11 IS NOT NULL AND R03AO11 > 0)
) AS min_tag_history
GROUP BY LEFT(t_stamp, 10)
ORDER BY t_stamp