我正在尝试使用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。
无论如何,您应该在此处使用严格的布尔语法:

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/

10-11 05:21