This is how I solved the problem sir. It seems like tricky when I tried myself to solve it. with cte1 as (select query_name, count(rating) as total_ratings, round((sum(rating/ position) / count(position)), 2) as quality from queries group by query_name ), cte2 as ( select query_name, count(rating) as req_rating from queries where rating < 3 group by query_name ) select cte1.query_name as query_name, cte1.quality as quality, case when round((cte2.req_rating / cast(cte1.total_ratings as float) ) * 100,2) is null then 0 else round((cte2.req_rating / cast(cte1.total_ratings as float) ) * 100,2) end as poor_query_percentage from cte1 left join cte2 on cte1.query_name = cte2.query_name where cte1.query_name is not null; But the way you taught it is splendid sir. Thank you so much sir . Thanks for the approach ❤sir
@justcodeitbro13122 ай бұрын
there is one test case for query_name = Null just put where query_name is not null group by query_name you will pass all the test cases
@ritwiksingh59439 ай бұрын
This solution misses a test case. Try the below query to get the answer submitted on leetcode: select query_name,round(avg(rating/position),2) as quality, round(100*(avg(case when rating
@containthis4450 Жыл бұрын
I am new to DA and SQL, you are awesome.. you are one of the few that can actually explain and code at the same time. Some people can code but cant teach and then there is you. you can coach and code at the same time and make practical explanation.. well done again,,
@containthis4450 Жыл бұрын
always remember that this is an easy question, but this code is not simple to a beginner. select query_name, round (sum(rating/position)/count(*),2) as quality, Round (sum(case when rating < 3 then 1 else 0 end)/count(*)*100,2) as poor_query_percentage from Queries group by query_name;
@VikashKumar-sn8zj Жыл бұрын
thanks
@sharankarchella26889 ай бұрын
this code does'nt satisfy all test cases if any query_name(dog or cat) is null
@ChandraTanikonda8 ай бұрын
@@sharankarchella2688 write( where query_name is not null) before group by
@containthis4450 Жыл бұрын
I love the way you explain code but please make the code simple for us new guys..
@k_aryal Жыл бұрын
The pace and explanation is perfect.
@AakifKhan-h9e2 ай бұрын
Yeh question Easy mae dal rakha hai, its should be in moderate
@adityams1659 Жыл бұрын
without CTE SELECT query_name, round(avg(rating::decimal / POSITION),2) AS quality, round(count(CASE WHEN rating
@sohailkan17 Жыл бұрын
does using CTE impacts execution performance by any means ?
WITH cte as (SELECT query_name, rating/position as ratio, CASE WHEN rating < 3 THEN 1 ELSE 0 END AS percent FROM Queries WHERE query_name IS NOT null) SELECT query_name, ROUND(AVG(ratio),2) AS quality, ROUND(SUM(percent) / COUNT(*) * 100, 2) AS poor_query_percentage FROM cte GROUP BY query_name
@laumatthew712 жыл бұрын
Clear explanation, thank you sir !
@EverydayDataScience2 жыл бұрын
Glad that you found it useful, Lau.
@VikashKumar-sn8zj Жыл бұрын
i don't understand anything what do I to understand to easily
@VikashKumar-sn8zj Жыл бұрын
मुझे कुछ भी समझ में नहीं आ रहा है कि मैं क्या करूं जो आसानी से समझ आ जाए