表1:Attendee_Login
列:id_event, login_id(primary key),attendee_status
表2:Decline_Handshake
列:id_handshake(primary), id_event, from_id(foreign key of Attendee_Login.login_id), to_id(foreign key of Attendee_Login.login_id)
我要查询
(Attendee_Login.login_id,
count(Decline_Handshake.from_id == Attendee_Login.login_id), count(Decline_Handshake.to_id == Attendee_Login.login_id)
)
条件是Decline_Hanshake
中的外键在attendee_status == 0
表中必须有Attendee_Login
。
我可以知道怎么做吗?我尝试为from_handshake
和to_handshake
创建2个子查询并加入主查询,但最终以相同的结果填充所有Attendee_Login.login_id