[英]SqlAlchemy Case with multiple conditions
我正在尝试做这样的事情:
x = db_session.query(
Candidate,
func.count(case([(Jobs.interview_type == 'PHONE_SCREEN' and Jobs.interview_type == 'INCLINED' , 1)])),
func.count(case([(Jobs.interview_type == 'PHONE_SCREEN' and Jobs.interview_type == 'NOT_INCLINED', 1)])),
func.count(case([(Jobs.interview_type == 'IN_HOUSE', 1)])),
func.count(case([(Jobs.interview_type == 'EVALUATION', 1)]))
).\
join(Jobs, Jobs.candidate_id == Candidate.candidate_id).\
filter(Candidate.candidate_id == '6236738').\
first()
但是, case
它没有处理第二个条件。 这可能吗?
我让它与and_
一起使用,但是没有给出正确的答案
func.count(case([(and_(Jobs.interview_type == 'PHONE_SCREEN', Jobs.interview_type == 'INCLINED'), 1)])),
应该返回2,但返回0
您需要使用sqlalchemy.and_
而不是and
运算符:
and_(Jobs.interview_type == 'PHONE_SCREEN',
Jobs.interview_type == 'INCLINED')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.