Say I have some data in table, which has the names and ages of customers who came into a store each day (the id functions as a unique day identifier).
id, obj
-----------------------------------------------------------------
1, [{'name': 'jenny', 'age':22}, {'name': 'adam', 'age':32},...]
2, [{'name': 'adam', 'age':32}, {'name': 'beth', 'age':27},...]
What I'd like to do is find the average age per day
SELECT id, AVG([o['age'] for o in obj]) AS avg_age
FROM t
And the desired output
id, avg_age
--, -------
1, 27
2, 29.2
This obviously doesn't work because the python-like list comprehension doesn't work in SQL. What is the proper way to do this in SQL?