因此,查询A接受查询B的结果(4个数字的列表)并对此进行查询。我该如何使用语法?当我只有1个值用作输入时,SQL似乎才喜欢。有什么建议吗?

select servers.hostname,
SUM(enm_amos_commands.successcount) AS successCommandCount,
SUM(enm_amos_commands.failurecount) AS failedCommandCount,
ROUND(AVG(enm_amos_commands.successcount+enm_amos_commands.failureCount),0) AS avg_per_minute,
MAX(enm_amos_commands.successcount+enm_amos_commands.failureCount) AS max_per_minute

from enm_amos_commands, servers
where servers.id IN
(
SELECT
    servers.id
FROM
    servers
WHERE
    servers.hostname LIKE '%111-scp%' or servers.hostname LIKE '%111-amos%'
    and servers.siteid = 6)

最佳答案

只需使用join。我猜你打算:

select s.hostname,
       SUM(eac.successcount) AS successCommandCount,
       SUM(eac.failurecount) AS failedCommandCount,
       ROUND(AVG(eac.successcount + eac.failureCount), 0) AS avg_per_minute,
       MAX(eac.successcount + eac.failureCount) AS max_per_minute
from enm_amos_commands eac join
     servers s
     on eac.server_id = s.id
where (s.hostname like '%111-scp%' or s.hostname LIKE '%111-amos%') and
      s.siteid = 6
group by s.hostname;

关于mysql - SQL:在结果列表上运行嵌套查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48064797/

10-10 10:48