SELECT * FROm streaming where genre like '%kids%'
or genre like '&family&'
or genre like '%children%';
when I run these query 171 rows returns.
select service,
count( case when genre like '%kids%'
or genre like '&family&'
or genre like '%children%' then 1.0000 or 0.0000 end ) as perc_family
from streaming
group by service
order by perc_family;
I want to find the percentage of content geared towards children by each platform.
CodePudding user response:
Use "/" . Divide all numbers by total
select service,
(count( case when genre like '%kids%'
or genre like '&family&'
or genre like '%children%' then 1.0000 or 0.0000 end )/count(*)) as perc_family
from streaming group by service order by perc_family;
CodePudding user response:
I think it is not the best solution, but I think it works:
SELECT sums.service, sums.perc_family * 100 / total.s AS `percent of total`
FROM (SELECT service,
COUNT(CASE WHEN genre like '%kids%'
OR genre like '