In a django setting, given a table with columns
`id`,`x`,`y`,`z`
I need to
groupby
ony
- find the maximum value of
z
in each group join the outcomes back such that I end up with a table reading
id
,x
,y
,z
,max_z
I managed to get the group maxima via
max_z = table.objects.values('y').annotate(max_z = Max('z'))
However, I am struggling in the "join back" operation.
If I traverse the new query as
max_z.values('id','x','y','z','max_z')
then the column max_z
and z
read equal. i.e.
`max_z == z` for each `id`
thus max_z
does not represent anymore the max value for each group.
For instance, in pandas background, the operation here would read
df['max_z'] = df.groupby('y').z.transform('max')
Any help appreciated