Thank you for sharing. This was really helpful in understanding How you break down the syntax and the problem with the solution. Looking forward to seeing more practice videos. Also, how do you find practice queries like this one ?
I’m glad you liked this video. Hey there is only one way to learn these queries - Practice. Once you start practising then you would automatically get the solution. Practising the solve and not cramming is the way to go ahead. Thanks for your input 👍
I was confused first then I saw that you are applying case with comparison winner column then wrote solution hit. with cte as ( select home_team, case when home_team = winner then 1 else 0 end as winner_flag from cricket_tournament union all select away_team, case when away_team = winner then 1 else 0 end as winner_flag from cricket_tournament ) select home_team, count(home_team) as total_matches_played, sum(winner_flag) as matches_won, count(case when winner_flag=0 then 0 end) as Matches_lost from cte group by home_team order by home_team
Hi Data Enthusiasts, how many of you are able to solve this problem? Do you have any other solution to this problem statement?
Appreciate your great work! Working on real examples is best method for learning, thanks!
Thanks Michal, yes it is true, working on real life projects will help in becoming job ready.
Thank you so much
You're most welcome. I am happy you got benefitted from this video.
Thank you for sharing. This was really helpful in understanding How you break down the syntax and the problem with the solution. Looking forward to seeing more practice videos. Also, how do you find practice queries like this one ?
I’m glad you liked this video. Hey there is only one way to learn these queries - Practice. Once you start practising then you would automatically get the solution. Practising the solve and not cramming is the way to go ahead.
Thanks for your input 👍
I was confused first then I saw that you are applying case with comparison winner column then wrote solution hit.
with cte as (
select home_team,
case when home_team = winner then 1 else 0 end as winner_flag
from cricket_tournament
union all
select away_team,
case when away_team = winner then 1 else 0 end as winner_flag
from cricket_tournament
)
select home_team, count(home_team) as total_matches_played, sum(winner_flag) as matches_won, count(case when winner_flag=0 then 0 end) as Matches_lost
from cte group by home_team order by home_team