我有一个表需要更新为Y的值,但此更新基于其他表的一些结果,我不知道如何执行此操作。
基本上,我需要完成以下检查
我的方法是使用UNION,但我希望有人告诉我这种方法是否正确或是否有更好的方法:
SELECT '1'
FROM t_A_Outbound
Where NOT HEADER IN (Select HEADER FROM t_B_Outbound)
UNION
SELECT '1'
FROM t_A_Outbound
Where HEADER IN (Select HEADER FROM t_B_Outbound
WHERE NOT INCOMPLETE ='Y')
UNION
Select '1'
From t_C_Outbound
Where ValueString = ''
UNION
Select '1'
From t_C_Outbound
WHERE Exists(Select Count(key), HEADER
From t_C_Outbound IN (SELECT HEADER FROM table_that_needs_updating)
Group By HEADER
Having NOT Count(Cast(key as Int)) = 19)
我想用1作为标志来说明这个值是否会回来更新我需要更改的表中的字段。
有人可以告诉我吗?
答案 0 :(得分:0)
我不清楚工会为你做什么。
您需要更新语句,例如:
update table
set y = . . .
where header in (Select header
From t_C_Outbound
Group By HEADER
Having Count(*)= 19 and
count(KEY) = count(*)
) and
header in (select header
from other table
group by header
having sum(case when col = 'Y' then 1 else 0 end) = 0
)
等等。您没有清楚地描述问题以提供更详细的代码。