SQL query to django

45 views
Skip to first unread message

Eugene TUYIZERE

unread,
Oct 9, 2021, 4:52:57 AM10/9/21
to django...@googlegroups.com
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


carlos

unread,
Oct 9, 2021, 7:38:53 PM10/9/21
to django...@googlegroups.com
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

Cheers

--
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...@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.


--
att.
Carlos Rocha

Sebastian Jung

unread,
Oct 10, 2021, 5:49:25 AM10/10/21
to django...@googlegroups.com
Hello Eugene, 

You can also take a raw query...


Regards

Eugene TUYIZERE

unread,
Oct 10, 2021, 5:55:20 AM10/10/21
to django...@googlegroups.com
Thank y'all



--
TUYIZERE Eugene

Msc Degree in Mathematical Science

African Institute for Mathematical Sciences (AIMS Cameroon)
Crystal Garden-Lime, Cameroon


Bsc in Computer Science

UR-Nyagatare Campus

Email: eugene....@aims-cameroon.org
           eugenet...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38
Reply all
Reply to author
Forward
0 new messages