SQL:在结果列表上运行嵌套查询

时间:2018-01-02 16:49:27

标签: mysql sql

因此,查询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)

1 个答案:

答案 0 :(得分:0)

只需使用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;