fix null return query
This commit is contained in:
parent
de860d9173
commit
a5138ed6a5
@ -24,9 +24,9 @@ SELECT
|
|||||||
l.address,
|
l.address,
|
||||||
l.thumbnail,
|
l.thumbnail,
|
||||||
l.submitted_by,
|
l.submitted_by,
|
||||||
r.regency_name,
|
COALESCE(r.regency_name, '') as regency_name,
|
||||||
p.province_name,
|
COALESCE(p.province_name, '') as province_name,
|
||||||
r2.region_name,
|
COALESCE(r2.region_name, '') as region_name,
|
||||||
u.username as submitted_by_user
|
u.username as submitted_by_user
|
||||||
FROM locations l
|
FROM locations l
|
||||||
JOIN regencies r on r.id = l.regency_id
|
JOIN regencies r on r.id = l.regency_id
|
||||||
|
@ -22,9 +22,9 @@ type GetTopListLocationsRow struct {
|
|||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
GoogleMapsLink string `json:"google_maps_link"`
|
GoogleMapsLink string `json:"google_maps_link"`
|
||||||
RegencyName string `json:"regency_name"`
|
RegencyName string `json:"regency_name"`
|
||||||
CriticScore sql.NullInt32 `json:"critic_score"`
|
CriticScore int16 `json:"critic_score"`
|
||||||
CriticCount int16 `json:"critic_count"`
|
CriticCount int16 `json:"critic_count"`
|
||||||
UserScore sql.NullInt32 `json:"user_score"`
|
UserScore int16 `json:"user_score"`
|
||||||
UserCount int16 `json:"user_count"`
|
UserCount int16 `json:"user_count"`
|
||||||
TotalCount int16 `json:"total_count"`
|
TotalCount int16 `json:"total_count"`
|
||||||
CriticBayes int16 `json:"critic_bayes"`
|
CriticBayes int16 `json:"critic_bayes"`
|
||||||
@ -46,9 +46,9 @@ func (q *Queries) GetTopListLocations(ctx context.Context, arg GetTopListLocatio
|
|||||||
FROM(
|
FROM(
|
||||||
SELECT
|
SELECT
|
||||||
*,
|
*,
|
||||||
(SELECT 5 * 4 + coalesce(critic_score, 0) * coalesce(critic_count, 0) / 5 + coalesce(critic_count, 0)) as critic_bayes,
|
(SELECT 5 * 4 + COALESCE(critic_score, 0) * COALESCE(critic_count, 0) / 5 + COALESCE(critic_count, 0)) as critic_bayes,
|
||||||
(SELECT 50 + coalesce(user_score, 0) * coalesce(user_count, 0) / 50 + coalesce(user_count, 0)) as user_bayes,
|
(SELECT 50 + COALESCE(user_score, 0) * COALESCE(user_count, 0) / 50 + COALESCE(user_count, 0)) as user_bayes,
|
||||||
((SELECT 50 + coalesce(user_score, 0) * coalesce(user_count, 0) / 50 + coalesce(user_count, 0)) + (SELECT 5 * 4 + coalesce(critic_score, 0) * coalesce(critic_count, 0) / 5 + coalesce(critic_count, 0)) ) / 2 as avg_bayes
|
((SELECT 50 + COALESCE(user_score, 0) * COALESCE(user_count, 0) / 50 + COALESCE(user_count, 0)) + (SELECT 5 * 4 + COALESCE(critic_score, 0) * COALESCE(critic_count, 0) / 5 + COALESCE(critic_count, 0)) ) / 2 as avg_bayes
|
||||||
|
|
||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
@ -59,9 +59,9 @@ func (q *Queries) GetTopListLocations(ctx context.Context, arg GetTopListLocatio
|
|||||||
l.google_maps_link,
|
l.google_maps_link,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
re.regency_name,
|
re.regency_name,
|
||||||
(SELECT SUM(score) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_score,
|
(SELECT COALESCE(SUM(score), 0) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_score,
|
||||||
(SELECT COUNT(id) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_count,
|
(SELECT COUNT(id) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_count,
|
||||||
(SELECT SUM(score) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_score,
|
(SELECT COALESCE(SUM(score), 0) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_score,
|
||||||
(SELECT COUNT(id) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_count
|
(SELECT COUNT(id) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_count
|
||||||
FROM locations l
|
FROM locations l
|
||||||
JOIN regencies re on re.id = l.regency_id
|
JOIN regencies re on re.id = l.regency_id
|
||||||
|
@ -149,9 +149,9 @@ SELECT
|
|||||||
l.address,
|
l.address,
|
||||||
l.thumbnail,
|
l.thumbnail,
|
||||||
l.submitted_by,
|
l.submitted_by,
|
||||||
r.regency_name,
|
COALESCE(r.regency_name, '') as regency_name,
|
||||||
p.province_name,
|
COALESCE(p.province_name, '') as province_name,
|
||||||
r2.region_name,
|
COALESCE(r2.region_name, '') as region_name,
|
||||||
u.username as submitted_by_user
|
u.username as submitted_by_user
|
||||||
FROM locations l
|
FROM locations l
|
||||||
JOIN regencies r on r.id = l.regency_id
|
JOIN regencies r on r.id = l.regency_id
|
||||||
@ -167,9 +167,9 @@ type GetLocationRow struct {
|
|||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Thumbnail sql.NullString `json:"thumbnail"`
|
Thumbnail sql.NullString `json:"thumbnail"`
|
||||||
SubmittedBy int32 `json:"submitted_by"`
|
SubmittedBy int32 `json:"submitted_by"`
|
||||||
RegencyName sql.NullString `json:"regency_name"`
|
RegencyName string `json:"regency_name"`
|
||||||
ProvinceName sql.NullString `json:"province_name"`
|
ProvinceName string `json:"province_name"`
|
||||||
RegionName sql.NullString `json:"region_name"`
|
RegionName string `json:"region_name"`
|
||||||
SubmittedByUser string `json:"submitted_by_user"`
|
SubmittedByUser string `json:"submitted_by_user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user