任何人都可以帮助我重写一个SQL查询,如下所示:有一个子查询需要重复。如何重写包含重复的子查询的SQL查询?
update policy
set totalvehicles = (
select count(*) from riskunit
where riskunit.policyId = policy.id
and riskunit.subtype = 7)
where policy.verified = '1'
and policy.Totalvehicles <(
select count(*)
from riskunit
where riskunit.policyId = policy.id
and riskunit.subtype = 7
);
谢谢!!
设置一个变量子查询的值,然后重复引用您使用的是什么类型的SQL Server的子查询 – steoleary 2014-10-22 11:18:16
的那个呢? sql-server,mysql ...? – ccheneson 2014-10-22 11:20:52
是否需要在1个查询中? – ccheneson 2014-10-22 11:51:17