我是sql的新手。我有一个问题涉及使用函数count()作为限制我的sql中的where子句。
tbl_meeting
ID
TIMESTAMP
CAPACITY
...
tbl_attendance
ID
NAME
...
(我之间也有一张桌子,因为多次出席可以参加多个会议)
我想选择所有已满的会议。它应该看起来像这样,但我可以弄明白。
select *
, count(LAM.id) as amount_attending
from tbl_meetings M
left join tbl_lnk_attendance_meeting LAM
on M.id = LAM.meeting_id
where M.capacity <> amount_attending
感谢。
答案 0 :(得分:1)
使用此方法可以完全参加会议
SELECT *
FROM tbl_meetings M
WHERE M.capacity = (SELECT COUNT(LAM.id)
FROM tbl_lnk_attendance_meeting LAM
WHERE M.id = LAM.meeting_id)
答案 1 :(得分:0)
试试这个:
select * , count(LAM.id) as amount_attending
from tbl_meetings M
left join tbl_lnk_attendance_meeting LAM
on M.id = LAM.meeting_id
group by LAM.id
答案 2 :(得分:0)
您已经在select语句中执行count函数,因此您的where子句只需要与数字进行比较。
select *
, count(LAM.id) as amount_attending
from tbl_meetings M
left join tbl_lnk_attendance_meeting LAM
on M.id = LAM.meeting_id
where amount_attending = (whatever number constitutes a full meeting)