python - 具有多个条件的 SqlAlchemy 案例
问题描述
我正在尝试做这样的事情:
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')
推荐阅读
- powershell - AutomationFocusChangedEventHandler:在 powershell 中未触发事件
- android - 具有多进程的 Workmanager
- python - 我无法让这个反应时间测试仪将信息输出到 csv 文件
- swift - 如何将通用视图添加到 LibraryContentPrivider
- pingfederate - 在 PingFed 中,如何在本地重建我的设置,以便我导入的属性文件生效?
- azure - 混合 AAD - 具有仅云密码的用户 ID
- java - 为什么没有添加新节点?
- r - R数据转换:数据框到填充0和1的矩阵
- r - 从具有 R 中指定概率的分组数据帧中采样
- php - 如何使用 Eloquent ORM 进行多重连接查询