我如何使其他情况下(在有条件的情况下)mysql

时间:2020-10-14 08:29:01

标签: mysql case-when

我有这个查询

SELECT dcp.discount_campaign_id, CASE  WHEN dcp.active = 0 
    THEN dcp.product_id ELSE (pc.category_id where c.sku_code is NOT NULL)
    END as discount_campaign_product
    FROM discount_campaign_product dcp 
    JOIN product_categories pc
    ON dcp.product_id = pc.product_id
    JOIN categories c
    ON pc.category_id = c.category_id

基本上我有3个表连接在一起,分别是Discount_campaign_product dcp,product_categories pc和category c

with dcp.product_id = pc.product_id 和pc.category_id = c.id

所以基本上我想输入大小写,如果dcp.active = 0然后插入dcp.product_id,但是如果active!= 0 然后将pc.category_id where放入pc.category_id具有c.sku_code NOT NULL

那是我编写的,但是格式错误,如何正确查询?

0 个答案:

没有答案