hiling_go/db/queries/locations.sql

30 lines
1016 B
MySQL
Raw Normal View History

2023-09-13 21:42:04 +07:00
-- name: GetListLocations :many
2023-09-14 13:49:03 +07:00
SELECT * FROM locations;
2023-09-13 21:42:04 +07:00
2023-09-14 22:51:01 +07:00
-- name: GetListRecentLocationsWithRatings :many
SELECT
l.id,
name,
thumbnail,
2023-09-20 13:37:14 +07:00
COALESCE(re.regency_name, '') as regency_name,
COALESCE(pr.province_name, '') as province_name,
(SELECT COALESCE(SUM(score), 0) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_score,
2023-09-14 22:51:01 +07:00
(SELECT COUNT(id) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_count,
2023-09-20 13:37:14 +07:00
(SELECT COALESCE(SUM(score), 0) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_score,
2023-09-14 22:51:01 +07:00
(SELECT COUNT(id) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_count
FROM locations l
JOIN regencies re on re.id = l.regency_id
2023-09-20 13:37:14 +07:00
JOIN provinces pr on re.province_id = pr.id
2023-09-14 22:51:01 +07:00
WHERE approved_by IS NOT NULL
ORDER BY l.created_at ASC
LIMIT $1;
2023-09-20 13:37:14 +07:00
-- name: GetLocationTag :many
SELECT
name
FROM tags
WHERE tags_type = 'location'
AND
target_id = $1
AND
approved_by IS NOT NULL;