https://platform.stratascratch.com/coding/10049-reviews-of-categories?code_type=3
Find the top business categories based on the total number of reviews. Output the category along with the total number of reviews. Order by total reviews in descending order.
yelp_business
business_id:
varchar
name:
varchar
neighborhood:
varchar
address:
varchar
city:
varchar
state:
varchar
postal_code:
varchar
latitude:
float
longitude:
float
stars:
float
review_count:
int
is_open:
int
categories:
varchar
答案是:
select 1
union all
select n+1 from num where n<12
)
select
substring_index(substring_index(categories,’;’,n),’;’,-1) as category,
sum(review_count) as review_cnt
from
yelp_business
inner join
num
on
n <= char_length(categories) - char_length(replace(categories,’;’,’’)) + 1
group by
category
可以求老师和uu们解释一下吗