select SUM(pass_count) ,SUM(fail_count),SUM(blocked_count),SUM(no_run_count)
from TAble1(nolock) table1
where owasp_id = (1,2,3,4,5,8)
inner join
Table 2 table2
on
TAble1.build_detail_id = table2.build_detail_id
where
TAble1.build_detail_id in(
select top 6 bdt.build_detail_id from table3 bdt order by 1 desc)
and table1.test_run_id=1
我收到语法错误,我希望获得passcount的总和,失败计数,其中owasp_id = 1,2,3,4,5,8,并使用表2进行内部联接以获取构建详细信息ID。任何人都可以帮忙吗?
答案 0 :(得分:1)
有三种语法错误,前两种会破坏查询,第三种是强烈建议:
WHERE
应该在FROM
和任何JOIN
条款之后。owasp_id = (1,2,3,4,5,8)
应为owasp_id IN (1,2,3,4,5,8)
。 WITH
表格提示(NOLOCK
),应该避免使用。因此查询应该如下所示:
select SUM(pass_count) ,SUM(fail_count),SUM(blocked_count),SUM(no_run_count)
from Table1 WITH (nolock) table1
inner join Table2 table2 on TAble1.build_detail_id = table2.build_detail_id
where owasp_id IN (1,2,3,4,5,8)
AND Table1.build_detail_id in(
select top 6 bdt.build_detail_id from table3 bdt order by 1 desc)
and table1.test_run_id=1
查询是否按预期工作我不能说,但至少在语法上应该是正确的。