gpt4 book ai didi

SQL,如何将逻辑 ('not in' 转换为 'not exists' )

转载 作者:行者123 更新时间:2023-12-02 04:45:48 26 4
gpt4 key购买 nike

Delete From StudentTb Where StudentType in (1, 2) and StudentI not in
(
Select lg.StudentI From StudentLog lg
)

我尝试将上面的代码改成下面的...但是,我不确定它是否正确。

Delete From StudentTb Where StudentType in (1, 2) 
and Not Exists
(
Select 'x'
From StudentLog lg
Where StudentI= lg.StudentI
)

谁能帮帮我?

最佳答案

你做错的只是没有在子查询中指定正确的别名:

Delete From StudentTb Where StudentType in (1, 2) 
and Not Exists
(
Select 'x'
From StudentLog lg
Where StudentTb.StudentI= lg.StudentI
)

注意 - select 语句中的列不会影响最终结果,但仍然首选编写 * 而不是 'x'

关于SQL,如何将逻辑 ('not in' 转换为 'not exists' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19818669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com