0
我正在獲取所有類別並加入具有帖子類別的item_category的類別表。 我的SQL就是這樣如何使用if語句選擇peewee
SELECT category.*,IF(item_category.category_id=NULL, 0,1) is_selected
FROM category
LEFT JOIN item_category ON category.category_id=item_category.category_id AND item_id=1
我試過,但沒有奏效。因爲如果使用python拋出錯誤如果
Category.select(Category, ItemCategory, fn.if(ItemCategory.category_id==None, 0, 1))
if語句的正確用法是什麼? 謝謝。
我不熟悉'IF',但你也可以使用'case'。有關詳細信息,請查看案例文檔:http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#case – coleifer 2014-10-20 15:37:31
@coleifer謝謝。你可以找到關於「mysql if」的信息http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if – Alexander 2014-10-20 15:41:47