gpt4 book ai didi

mysql - 如何让 MySQL case 语句在存储过程中工作?

转载 作者:行者123 更新时间:2023-11-29 08:51:28 27 4
gpt4 key购买 nike

我正在尝试使用 MySQL CASE 语句从产品表中选择产品。

我有这个:

SELECT art.a,art.b,art.c
FROM products AS art
WHERE art.inventory != "0"
# filter by param_reference_iln (seller ID = vARCHAR(13) )
CASE
WHEN param_reference_iln = '3333333333333' THEN AND art.iln = '1111111111111' OR art.iln = '2222222222222'
WHEN param_reference_iln = '8888888888888' THEN AND art.iln = '7777777777777'
ELSE AND art.iln NOT IN ('1111111111111','2222222222222','7777777777777')
END CASE;

我已经尝试了 CASE variants ,但我都无法工作。

问题:
我究竟做错了什么?

最佳答案

我不确定 WHERE 子句中是否可以包含 CASE。不管怎样,你应该在这里使用严格的 bool 语法:

SELECT art.a,art.b,art.c
FROM products AS art
WHERE art.inventory != "0"
AND (
(param_reference_iln = '3333333333333' AND (art.iln = '1111111111111' OR art.iln = '2222222222222'))
OR
(param_reference_iln = '8888888888888' AND art.iln = '7777777777777')
OR
art.iln NOT IN ('1111111111111','2222222222222','7777777777777')
);

关于mysql - 如何让 MySQL case 语句在存储过程中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11099625/

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