python peewee - 如何使用distinct

Era*_*ans 11 python-2.7 peewee

我试图让这个代码与peewee一起工作:

distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
print distinct_list
Run Code Online (Sandbox Code Playgroud)

但是打印命令结果是:

<class '__main__.QSales'> SELECT DISTINCT t1.`Account`, t1.`Tax_Code` FROM `q_sales` AS t1 WHERE (t1.`Trans_#` = %s) [3717]
Run Code Online (Sandbox Code Playgroud)

在MySQL编辑器中运行上面的select语句(将打印结果复制到编辑器)返回正确的结果.

我也尝试过:

distinct_list = QSales.select(fn.Distinct(QSales.account, QSales.tax_code)).where(QSales.trans_num == 3717)
Run Code Online (Sandbox Code Playgroud)

但得到了相同的结果

我究竟做错了什么?

谢谢.

Era*_*ans 13

睡在上面,我意识到该代码应该如下:

distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
for item in distinct_list:
    print item.account
    print item.tax_code
Run Code Online (Sandbox Code Playgroud)

这个现在关闭了.谢谢.

  • 很高兴你解决了 (2认同)