This repository was archived by the owner on Jan 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.sql
More file actions
77 lines (77 loc) · 1.85 KB
/
query.sql
File metadata and controls
77 lines (77 loc) · 1.85 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
SELECT
dist.name,
dist_info.title,
dist_info.short_note,
imgs.images,
ara.areas,
plc.places,
trans.transports
FROM
gg_districts dist
JOIN
gg_districts_info dist_info
ON dist_info.dist_id = dist.id
JOIN LATERAL (
SELECT json_agg(
json_build_object(
'image', dt_imgs.image,
'altText', dt_imgs.image_alt
)
) AS images
FROM
gg_districts_imgs AS dt_imgs
WHERE
dt_imgs.dist_id = dist.id
FETCH FIRST 15 ROW ONLY
) imgs on TRUE
LEFT JOIN LATERAL (
SELECT json_agg(
json_build_object(
'name', area.name,
'slug', area.slug,
'image', area.card_img
)
) AS areas
FROM
gg_areas AS area
WHERE
area.dist_id = dist.id
AND area.is_active = TRUE
) ara ON TRUE
LEFT JOIN LATERAL(
SELECT json_agg(
json_build_object(
'name', dist_plc.name,
'slug', dist_plc.slug,
'image', dist_plc.card_img,
'altText', dist_plc.card_img_alt
)
) AS places
FROM
gg_places as dist_plc
LEFT JOIN
gg_areas AS ar
ON ar.dist_id = dist_plc.dist_id
AND ar.id = dist_plc.area_id
WHERE
dist_plc.is_districttop = TRUE
AND dist_plc.dist_id = dist.id
) plc ON TRUE
LEFT JOIN LATERAL (
SELECT json_agg(
json_build_object(
'name', ts.name,
'shortName', ts.short_name
)
) AS transports
FROM
transit_systems_dist AS dist_trans
JOIN
transit_systems ts
ON ts.id = dist_trans.transit_id
WHERE
dist_trans.dist_id = dist.id
) trans ON true
WHERE
dist.slug = 'hapur'
AND dist.is_active = TRUE;