gpt4 book ai didi

SQL In子句值

转载 作者:行者123 更新时间:2023-12-03 23:59:14 25 4
gpt4 key购买 nike

我有以下SQL

Select * 
from PS_VENDOR
WHERE VENDOR IN ('111','222','333','444')

其中 444 VENDOR 不存在。但是当我运行 SQL 时,我应该从 IN CLAUSE 中获取所有 4 行所有供应商,对于 444,只需填充空白或“X”

我尝试了以下方法,但它不起作用

Select * 
from PS_VENDOR
WHERE NVL(VENDOR IN ('111','222','333','444'), 'X');

最佳答案

使用 CTE 来保持你的值(value)观,左连接

with V1 as
(
select '111' as VV from dual
union all
select '222' as VV from dual
union all
select '333' as VV from dual
union all
select '444' as VV from dual
)

select VV, PS_VENDOR.*

from V1
left join PS_VENDOR
on VENDOR = VV

关于SQL In子句值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40935004/

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