Skip to content

Latest commit

 

History

History
20 lines (20 loc) · 852 Bytes

1211. Queries Quality and Percentage.md

File metadata and controls

20 lines (20 loc) · 852 Bytes

1211. Queries Quality and Percentage

Question Link

Solution v1

# Write your MySQL query statement below
select query_name, round(avg(rating/position), 2) quality, round(avg(if (rating<3,1,0))*100, 2) poor_query_percentage from Queries
group by query_name

Solution v2

# Write your MySQL query statement below
select t.query_name, round(avg(t.quality),2) as quality, round(avg(t.poor_query_percentage),2) as poor_query_percentage from
(
    select query_name, sum(rating/position) as quality, if(rating<3,1,0)*100 as poor_query_percentage from Queries group by query_name, result, position, rating
) as t
where t.query_name is not null
group by query_name

Conclusion

Compare these 2 solutions... If you want a sum() maybe you just need a group by.