-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.sql
More file actions
43 lines (36 loc) · 1.24 KB
/
Copy pathanalytics.sql
File metadata and controls
43 lines (36 loc) · 1.24 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
-- Analytics queries for Supabase / PostgreSQL
-- 1. Average rating across all apps.
select round(avg(rating)::numeric,2) as average_rating from reviews;
-- 2. Total number of reviews.
select count(*) as total_reviews from reviews;
-- 3. Count of reviewed apps.
select count(distinct app_name) as reviewed_apps from reviews;
-- 4. Average rating and review count per app.
select app_name,
round(avg(rating)::numeric,2) as avg_rating,
count(*) as review_count
from reviews
group by app_name
order by avg_rating desc, review_count desc;
-- 5. Rating distribution.
select rating, count(*) as count
from reviews
group by rating
order by rating desc;
-- 6. Users with the most reviews.
select username,
count(*) as reviews_submitted
from reviews
group by username
order by reviews_submitted desc
limit 10;
-- 7. Decision suggestion summary.
select case
when avg(rating) >= 4.5 then 'Strongly recommend'
when avg(rating) >= 3.5 then 'Recommend'
when avg(rating) >= 2.5 then 'Consider with caution'
when avg(rating) >= 1.5 then 'Not recommended'
else 'Avoid'
end as decision_suggestion,
round(avg(rating)::numeric,2) as average_rating
from reviews;