Вопрос по python, sql – Джанго совокупные запросы с выражениями

7

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

>>> XYZ.all().aggregate(Max('a'))

... {'a__max': 10}

Error: User Rate Limit Exceeded

>>> XYZ.all().aggregate(Max('x/y'))

Error: User Rate Limit Exceeded

*** FieldError: Cannot resolve keyword 'x/y' into field. Choices are: a, b, x, y, id

Error: User Rate Limit Exceeded

>>> XYZ.all().aggregate(Max(F('x')/F('y')))

Error: User Rate Limit Exceeded

*** AttributeError: 'ExpressionNode' object has no attribute 'split'

Error: User Rate Limit Exceeded

XYZ.all().extra(select={'z':'x/y'}).aggregate(Max('z'))

Error: User Rate Limit Exceeded

FieldError: Cannot resolve keyword 'z' into field. Choices are: a, b, x, y, id

Error: User Rate Limit Exceeded

XYZ.all().extra(select={'z':'MAX(x/y)'})[0].z

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededF()Error: User Rate Limit Exceededpart of the upcoming Django 1.8 release. Adam Brenecki

Ваш Ответ

4   ответа
0

Book.objects.all().aggregate(price_per_page=Sum('price_per_page', 
                                                field='book_price/book_pages'))

2

F()

XYZ.all().aggregate(Max(F('x')/F('y')))

Sum()F():

Book.objects.all().aggregate(price_per_page=Sum(F('price')/F('pages'))
Error: User Rate Limit Exceeded Pedro Werneck
-3

result = XYZ.aggregate(Max('x'), Max('y'))

result['x__max'] \ result['y__max']
Error: User Rate Limit Exceeded Pedro Werneck
6

SELECT x/y, * FROM XYZ ORDER BY x/y DESC LIMIT 1;
# Or more verbose version of the #1
SELECT x/y, id, a, b, x, y FROM XYZ GROUP BY x/y, id, a, b, x, y ORDER BY x/y DESC LIMIT 1;
# Or
SELECT * FROM XYZ WHERE x/y = (SELECT MAX(x/y) FROM XYZ) LIMIT 1;

XYZ.objects.extra(select={'z':'x/y'}).order_by('-z')[0]
# Or
XYZ.objects.extra(select={'z':'x/y'}).annotate().order_by('-z')[0]
# Or x/y=z => x=y*z
XYZ.objects.filter(x=models.F('y') * XYZ.objects.extra(select={'z':'MAX(x/y)'})[0].z)[0]

XYZ.all().extra(select={'z':'MAX(x/y)'})[0].z

MAXGROUP BYzMAX(x/y).

Error: User Rate Limit Exceeded Pedro Werneck
Error: User Rate Limit ExceededXYZ.objects.extra(select={'z':'MAX(x/y)'})[0].zError: User Rate Limit Exceededcursor.execute('SELECT MAX(x/y) from XYZ')Error: User Rate Limit Exceeded

Похожие вопросы