gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:44:07 28 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/

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