关于不同表上主键的烧瓶sqlalchemy连接计数结果

时间:2018-06-25 07:09:47

标签: sqlalchemy flask-sqlalchemy

表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_handshaketo_handshake创建2个子查询并加入主查询,但最终以相同的结果填充所有Attendee_Login.login_id

0 个答案:

没有答案