问题
在Athena数据库中,使用json_extract_scalar函数对某个json字段进行过滤和分组统计。
Athena SQL
sql
SELECT
JSON_EXTRACT_SCALAR(all_json, '$["properties"]["$latest_utm_medium"]') as "latest_utm_medium",
COUNT(*) as record_count
FROM gule_table
WHERE event = '$MPViewScreen'
AND JSON_EXTRACT_SCALAR(all_json, '$["properties"]["$url_path"]') = 'pages/thirdPartner/page'
AND JSON_EXTRACT_SCALAR(all_json, '$["properties"]["$url_query"]') LIKE '%id=%'
AND "date" >= DATE('2025-12-04') AND "date" <= DATE('2025-12-07')
GROUP BY JSON_EXTRACT_SCALAR(all_json, '$["properties"]["$latest_utm_medium"]')
ORDER BY record_count DESC;