Skip to content
Advertisement

Sum of column values ​inside Json array with group by

I have next Django model.

I store JSON data in wh_data.

Note: it’s data for one row – 2022-06-06.

I need to calculate the sum inside stocks by grouping them by wh and by created_at so that the output is something like this

I know how to group by date, but I don’t understand how to proceed with aggregations inside JsonField.

A solution is suitable, both through Django ORM and through RAW SQL.

Advertisement

Answer

demo

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement