我的 SQL 查询有什么问题?
它不断返回以下错误WHERE building_id=:building_id
:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 5 行的 ':building_id AND WHERE NOT EXISTS ( SELECT 1 FROM ts_roompref ' 附近使用正确的语法:SELECT COUNT(*) totalCount FROM ts_room WHERE building_id=:building_id AND WHERE NOT存在(从 ts_roompref 中选择 1 加入 ts_request ON ts_roompref.request_id = ts_request.roompref_id AND day_id = 1 AND period_id = 1 WHERE ts_room.id = ts_roompref.room_id)
这是我的代码:
SELECT
COUNT(*) totalCount
FROM
ts_room
WHERE building_id=:building_id AND
WHERE
NOT EXISTS (
SELECT 1
FROM ts_roompref
JOIN ts_request
ON ts_roompref.request_id = ts_request.roompref_id
AND day_id = 1
AND period_id = 1
WHERE
ts_room.id = ts_roompref.room_id)
我在这里有一个 SQL 表 - http://sqlfiddle.com/#!2/30297/8