Mysql SQLite和If()条件
我尝试在SQLite中运行一个MySQL查询。 我发现Mysql SQLite和If()条件,mysql,sqlite,if-statement,case,Mysql,Sqlite,If Statement,Case,我尝试在SQLite中运行一个MySQL查询。 我发现IF条件在SQLite中不起作用,应该转换为CASE。 由于MySQL查询非常大,所以我希望有人能告诉我应该如何做。在许多其他MySQL查询中,我必须转换为SQLite 一旦我看到应该如何在我使用的查询中完成它(因为我熟悉它),我假设我可以为其他人处理它。 以下是应在SQLite中运行的MySQL: select p.products_model, pd.products_name, m.manufacturers_name, p.p
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
到
案例
当s.status 0和s.status不为空时
然后是美国特价商品、新产品、价格
否则无效
以特价商品、新产品、价格结尾,
案例
当s.status 0和s.status不为空时
然后是美国特价商品、新产品、价格
其他产品价格
以最终价格结束
我读了一些关于您的个人资料,也许您已经掌握了这些技能,但我想为您提供以下url:@wHiTeHaT:谢谢,我会查一查!)请你帮我研究另一个问题,它也是与sql相关的。在我的问题中,我假设在一个语句中执行两个查询。我想知道你是否可以验证我的假设…这里:在语句中的任何位置都有效(我在我的ORDER BY
子句中测试了此解决方案)。赞成票:)
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