gpt4 book ai didi

mysql - SQLite 和 If() 条件

转载 作者:行者123 更新时间:2023-11-29 01:24:07 25 4
gpt4 key购买 nike

我有一个试图在 SQLite 中运行的 MySQL 查询。我发现 IF 条件在 SQLite 中不起作用,应该转换为 CASE。由于 MySQL 查询非常大,无法进行概述,我希望有人能告诉我应该如何完成。在许多其他 MySQL 查询之一中,我必须转换为 SQLite。

一旦我看到应该如何在我使用的查询中完成它(因为我熟悉它),我假设我可以为其他人处理它。这是应该在 SQLite 中运行的 MySQL:

select 
p.products_model,
pd.products_name,
m.manufacturers_name,
p.products_quantity,
p.products_weight,
p.products_image,
p.products_id,
p.manufacturers_id,
p.products_price,
p.products_tax_class_id,
IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
from
products_description pd,
products p
left join manufacturers m on p.manufacturers_id = m.manufacturers_id
left join specials s on p.products_id = s.products_id,
products_to_categories p2c
where
p.products_status = "1" and
p.products_id = p2c.products_id and
pd.products_id = p2c.products_id and
pd.language_id = "1" and
p2c.categories_id = "10"

最佳答案

改变:

IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price

CASE
WHEN s.status <> 0 AND s.status IS NOT NULL
THEN s.specials_new_products_price
ELSE NULL
END AS specials_new_products_price,
CASE
WHEN s.status <> 0 AND s.status IS NOT NULL
THEN s.specials_new_products_price
ELSE p.products_price
END AS final_price

关于mysql - SQLite 和 If() 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7326738/

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