2011-09-06 211 views
1

我有一个MySQL查询,我试图在SQLite中运行。 我发现IF条件在SQLite中不起作用,应该转换为CASE。由于MySQL的查询很大,所以我希望有人能告诉我应该怎么做。在许多其他MySQL查询之一中,我必须转换为SQLite。SQLite和If()条件

一旦我看到它应该如何在我使用的查询中完成(因为我熟悉它),我认为我可以为其他人处理它。 这里是应该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" 

回答

4

变化:

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 
+0

谢谢你! (多少代码pfff,我会考虑更大的屏幕大声笑) – wHiTeHaT

+0

我收获了一些关于你的个人资料,或许你已经掌握了这些技能,但是我想为你提供这个网址:http:// html5sql。 com/index.html – wHiTeHaT

+0

@wHiTeHaT:谢谢,我会检查一下! :) – mwan