python - Django Query to find number of rows with a certain value greater than zero, grouped by user -


i have dataset such each user has integer score each date in date range.

i want find each user, number of days on he/she had greater 0 score - so, want group by user , count number of scores greater 0 each user.

how write such query in django 1.10?

the below equivalent select query grouping user , counting number of entries, objects score greater (gt) zero:

from django.db.models import count  results = myobject.objects.filter(score__gt=0).values('user').annotate(total=count('user')).order_by('user') 

which unless i'm mistaken you're asking for?


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -