Hi.

Technically that is impossible.

Group by is used to make sql aggregate to know aggregation criteria.

Let's take simple example:

Let's have table with columns name, job and salary.

Rows in table would be:

Jani,programmer,100
Ahmmed,programmer,100

Now lets calculate average salary of programmer:

select job, avg(salary) from table group by job

Now selecting name there doesn't make sense. If you would like actually
represent names with average  salary you can do that by joining temporary
table. So query would look like this:

select *,b.avg from table a join (select job, avg(salary) as "avg" from
table) b join a.job = b.job

This should be possible with pure django as well.


ke 18. syysk. 2019 klo 9.46 Shakil Ahmmed <shakilfci...@gmail.com>
kirjoitti:

>
> How to select all field but group by one field
> --
>
> <https://about.me/shakilahmmed?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api&utm_content=thumb>
> Shakil Ahmmed
> about.me/shakilahmmed
> <https://about.me/shakilahmmed?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api&utm_content=thumb>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BEpJfzNPZ_vRqyHan92VsDY9MAjsxogKVh4FEBdwXWLd%3DHXtQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2BEpJfzNPZ_vRqyHan92VsDY9MAjsxogKVh4FEBdwXWLd%3DHXtQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oerN_kMNvi%3DDJQXr9_oSWRncNO%2BmkbkbE7Naies%3DfTD_Q%40mail.gmail.com.

Reply via email to