I’ve 2 tables with below fields
fields: attribute_name, total, city _id, year, month
fields: id, city_name, state
and I want to perform group by on state and attribute_name and return all columns in attribute table.
please help me how to solve
Thanks in advance
Here’s a similar example i have done in the past.
It does the group by for the
year fields (that was annotated, but it does not need to be) on the first
values call, after that, you use
aggreate on your qs, lastly order it
from django.db.models import Count, Sum
qs = SomeModel.objects.filter(some_filter="foo")
values = (
Thank you for the response, It will group by month, year but as per my requirement It should group on attribute name and state and fetch_all fields in Attribute table, I will take reference of your code and will try