Reputation: 3538
I am trying to do something like this:
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()
However its not picking up the second condition in case
. Is this possible?
I got it working with and_
but its not giving the right answer
func.count(case([(and_(Jobs.interview_type == 'PHONE_SCREEN', Jobs.interview_type == 'INCLINED'), 1)])),
should return 2, but its returning 0
Upvotes: 3
Views: 6970
Reputation: 13009
You need to use sqlalchemy.and_
instead of the and
operator:
and_(Jobs.interview_type == 'PHONE_SCREEN',
Jobs.interview_type == 'INCLINED')
Upvotes: 3