ok, try this but is only idea (i don't is working)

from django.db.models import Count

result = (YY.objects
    .values('time_frame','status')
    .annotate(timecount=Count('time_frame'))
    .order_by('status')
)

read this for understand
https://docs.djangoproject.com/en/3.2/topics/db/aggregation/

if this no help you maybe this way

results = YY.objects.raw('SELECT status FROM YY GROUP BY time_frame')

and read this too for understand
https://docs.djangoproject.com/en/3.2/topics/db/sql/#topics-db-sql

Cheers

On Sat, Oct 9, 2021 at 2:52 AM Eugene TUYIZERE <eugenetuyiz...@gmail.com>
wrote:

> Dear all,
>
> I have a table let call it *YY*. Some fields in this table are status,
> time_frame, etc.
> time frame is in terms of years and status are Not started, In progress
> and Completed. I want to display all services Not started, in progress and
> completed in each year.
> And at the end to display this on bar chart. but What I most want is the
> query.
>
> I want to transform this SQL query in Django:
>
> SELECT status from YY group by time_frame;
>
> please assist
>
> --
> *TUYIZERE Eugene*
>
>
> --
> 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/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABxpZHsysRxgE9bn9c9naLY%2BtWmKRfwpr%2BUsMYiAV_ZcPC_3Hw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
att.
Carlos Rocha

-- 
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/CAM-7rO1KKmhjhCbFfO756tqwgOaKsAN-qiL-MhH%3D8KiGfbd9XQ%40mail.gmail.com.

Reply via email to