0

我正在尝试将这个“简单”的 SQL 语句映射到 SQL-Alchemy

    select DISTINCT cv.*, ct."name"
    from "CarVariants" cv,
    "Cars" ca,
    "CarTypes" ct
    where cv."f_keyNumber" = ca."keyNumber"
    and cv."carType" = ca."carType"
    and cv."carType" = ct."f_carType"
    and "f_keyNumber" = '12345'
    and "f_carId" = 1

像这样的东西:

variants = self.em.CarVariants.createQuery();

variants = variants.filter_by(f_keyNumber=12345, f_carId = 1).distinct()

如何添加“和”关系(汽车、汽车类型)?

4

1 回答 1

1

利用and_

from sqlalchemy import and_
variants = variants.filter_by(and_(cond_1,cond_2....cond_n)).distinct()

请参阅此页面以获取更多参考:
http ://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html

于 2013-06-25T21:37:48.027 回答