2011-09-06 209 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