我有以下疑问:
select
sites.denomination,
rooms.floor,
rooms.number,
(count(beds.id) - sum(if(beds.state<0,1,0))) as active
from rooms
join sites on rooms.site_id = sites.id
join beds on rooms.id = beds.room_id group by beds.room_id
order by
sites.denomination,
rooms.floor
它工作得很好,但是我想在站点上添加一个选择(field sites.id)。我总是得到一个错误:“你的SQL语法有错误;请检查手册…”
谢谢!
最佳答案
SELECT
sites.denomination,
rooms.floor,
rooms.number,
(COUNT(beds.id) - SUM(if(beds.state<0,1,0))) AS active
FROM rooms
JOIN sites ON rooms.site_id = sites.id
JOIN beds ON rooms.id = beds.room_id
//your WHERE should be here
GROUP BY beds.room_id
ORDER BY
sites.denomination,
rooms.floor
关于mysql - 在哪里放“哪里”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33567823/