Queryset to select maximum values per group - using mysql

Asked

Viewed 25 times

0

I am trying to select the highest values per group and I would like to receive all attributes from my table, tried this solution:

dropWorst1 = dropToday.values('line_nm').annotate(worst1=Max('err_ppm')).order_by('line_nm')

However, it only returns the fields: line_nm, worst1, how can I return all the fields of this line? I am using Mysql and tried this other solution: however it only works for postgress

dropWorst1 = dropToday.order_by('-err_ppm','line_nm').distinct('line_nm')

And the following error occurs:

DISTINCT ON Fields is not supported by this database backend

How can I recover all data from that line? These are the other fields in the table:

class SmdDropRateCe(models.Model):
    sumr_ymd = models.DateField(blank=True, null=True)
    line_nm = models.CharField(max_length=20, blank=True, null=True)
    shift_code = models.CharField(max_length=10, blank=True, null=True)
    model_code = models.CharField(max_length=30, blank=True, null=True)
    equip_id = models.CharField(max_length=30, blank=True, null=True)
    mat_code = models.CharField(max_length=30, blank=True, null=True)
    reel_no = models.CharField(max_length=10, blank=True, null=True)
    err_num = models.IntegerField(blank=True, null=True)
    pckp_num = models.IntegerField(blank=True, null=True)
    plac_num = models.IntegerField(blank=True, null=True)
    err_ppm = models.FloatField(blank=True, null=True)
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.