How to solve error “Operator 'getitem' is not supported on this expression” when using case()
问题 I'm trying to convert the following SQL into SQLAlchemy: select t1.id, t1.field_A, max(case when t2.field_B = 1 then t2.field_C end) test_2_field_b_1, max(case when t2.field_B = 2 then t2.field_C end) test_2_field_b_2 from test_1 t1 inner join test_2 t2 on t2.field_A = t1.field_A group by t1.id, t1.field_A I've got as far as: qry = session.query( Test1.id_, Test2.field_A, func.max(case((Test2.field_B.__eq__(1), "Test2.field_C"))).label("test_2_field_b_1"), func.max(case((Test2.field_B.__eq__