所以我有一张桌子,例如租来的物品
id | itemID | state
3 | 2 | 0
2 | 2 | 1
1 | 2 | 1
状态表示该项目是否在过去租用。0 = currently rented
包含项目的表:
id | item | condition
1 | showel | good
2 | saw | ok
现在我想选择当前未租用的物品,我最终得到了这个:
SELECT * FROM
(
SELECT CASE WHEN b.itemID = a.id AND b.state = 0 THEN 1
ELSE 0 END AS itemState, a.condition AS condition
FROM items AS a
LEFT JOIN rented AS b ON a.id = b.item_id
) AS states
WHERE states.itemState = 0
但是 SQL 返回的是 saw[id=2] 当前是免费的,但事实并非如此。
有什么办法可以修复 SQL 语句?
// 编辑:我需要在租用的表中保留重复的 itemID