0

当我执行此查询集时:

Club.objects.values('district').distinct()

我希望得到这个 SQL:

SELECT DISTINCT `club_club`.`district` FROM `club_club` ORDER BY `club_club`.`name` ASC

但是 Django 会生成这个查询(添加 'name' 列):

>>> print Club.objects.values('district').distinct().query
SELECT DISTINCT `club_club`.`district`, `club_club`.`name` FROM `club_club` ORDER BY `club_club`.`name` ASC

怎么了?

4

1 回答 1

0

如果您正在使用Query 您期望是无效 order by column的,则必须在其中,否则您将收到此标准 SQL 错误select listdistinct keyword

Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
于 2012-08-04T08:08:03.463 回答