python-2.7 - python peewee - 如何使用不同的

标签 python-2.7 peewee

我正在尝试使此代码与 peewee 一起使用:

distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
print distinct_list

但打印命令结果是:
<class '__main__.QSales'> SELECT DISTINCT t1.`Account`, t1.`Tax_Code` FROM `q_sales` AS t1 WHERE (t1.`Trans_#` = %s) [3717]

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

我也试过:
distinct_list = QSales.select(fn.Distinct(QSales.account, QSales.tax_code)).where(QSales.trans_num == 3717)

但得到了相同的结果

我究竟做错了什么?

谢谢你。

最佳答案

睡了过去,我意识到该代码应该如下所示:

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

现在已经关闭了。谢谢你。

关于python-2.7 - python peewee - 如何使用不同的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17596991/

相关文章:

python - PeeWee 是否支持与 MySQL View 的交互?

python - Python (2.7) 可用的数据结构是否比标准库中的标准列表、集合、元组字典更多?

python - Python 日志记录模块在多处理上下文中的令人困惑的行为

python - 如何使用peewee limit()?

python - Peewee - 用字典更新条目

python - 使用 SQLite 和 Peewee 并发写入

python-3.x - Peewee:使用 CompositeKey 的模型中的 create_or_get() 错误

python-2.7 - 在 Google Cloud Dataflow 中访问模板化运行时参数 - Python

python - 如何将大字典的对象以特定比例分配给较小的字典?

python - 如何使用python维护数组中数字出现的顺序?