I am using Mysql (version > 8).
I have a table where I am storing unique customer ids for the day in an JSON field as an array.
I need to query for all unique customers in last 30 days. I am unable to find an equivalent mysql query for the same.
I am using JSON_ARRAYAGG to first merge all the arrays and then I am using ruby to flatten the array and find uniq values.
Example Query:
SELECT
JSON_ARRAYAGG(customers) as customers,
name
FROM `source_type_daily_metrics`
WHERE
`source_type_daily_metrics`.`merchant_id` = 29
AND (date >= curdate() - interval 30 day)
GROUP BY `source_type_daily_metrics`.`name`