-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery-47dcef54f2d7b53f35623f5747b4a2dd89b45756b33e94879c2860ea5cb5f8df.json
28 lines (28 loc) · 2.25 KB
/
query-47dcef54f2d7b53f35623f5747b4a2dd89b45756b33e94879c2860ea5cb5f8df.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n COALESCE((\n WITH origins AS (\n SELECT DISTINCT(COALESCE(referrer, 'unknown')) AS referrer, COUNT(*) AS total\n FROM access_tokens_visits\n WHERE token_id = $1\n GROUP BY referrer\n )\n SELECT json_object_agg(referrer, total) FROM origins\n ), '{}') AS \"origins: JsonValue\",\n (\n WITH date_series AS (\n SELECT generate_series(\n NOW()::date - INTERVAL '30 days',\n NOW()::date,\n INTERVAL '1 day'\n )::date AS visit_date\n ),\n aggregated_visits AS (\n SELECT\n ds.visit_date,\n COALESCE(COUNT(atv.visited_at), 0) AS visit_count\n FROM\n date_series ds\n LEFT JOIN\n access_tokens_visits atv\n ON\n ds.visit_date = DATE(atv.visited_at) \n AND atv.token_id = $1\n GROUP BY\n ds.visit_date\n ORDER BY\n ds.visit_date\n )\n SELECT COALESCE(json_object_agg(\n TO_CHAR(visit_date, 'YYYY-MM-DD'),\n visit_count\n ), '{}') AS visits\n FROM aggregated_visits\n ) AS \"visits_30_days: JsonValue\"\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "origins: JsonValue",
"type_info": "Json"
},
{
"ordinal": 1,
"name": "visits_30_days: JsonValue",
"type_info": "Json"
}
],
"parameters": {
"Left": [
"Uuid"
]
},
"nullable": [
null,
null
]
},
"hash": "47dcef54f2d7b53f35623f5747b4a2dd89b45756b33e94879c2860ea5cb5f8df"
}