Assignment_3
Assignment_3
ipl_schema;
--1.Display each players salary in INR and USD. If Salary is not available, display
NULL
--3. Display the age of each player in below format. For example, the DOB is May 2
2023, display age as 1 year 5 months, 20 days
select player_name,
extract(year from age(current_date, date_of_birth::date)) as years || 'years' ||
extract(month from age(current_date, date_of_birth::date)) as months || 'months' ||
extract(day from age(current_date, date_of_birth::date)) as days || 'days' as age
from player_info;
--4.Split the full name of the player and display in separate columns as first name
and last name.
select split_part(player_name, ' ', 1) as first_name,
split_part(player_name, ' ', 2) as last_name
from player_info;
--5.Display all the different venues the IPL is played till now.
select VENUE from team_performance
group by venue;
--6. Display all the cities where IPL is played till now
select distinct(split_part(venue, ',', 2)) as city from team_performance;
--7.Display all the names of the players who have longer names than 10 letters?
select player_name from player_info
where length(player_name) > 10;
--8.Display run rate on each ball for all matches that played in 2016.
select match_id, innings_number,
round(sum((runs_scored + extra)::float)/ count(distinct ball_number), 2) as
run_rate
from ipl_ballbyball
group by match_id, innings_number;
--9. Display number of matches played on weekends during the 2019 season.?
SELECT COUNT(*) AS matches_on_weekends
FROM ipl_ballbyball
WHERE ((TO_CHAR(MATCH_DATE::date, 'Day') ILIKE '%Sun%')
OR (TO_CHAR(MATCH_DATE::date, 'Day') ILIKE '%Sat%'))
AND EXTRACT(YEAR FROM MATCH_DATE::date) = 2019;
--10. Assuming that every player will retire by 40 years. Display how many more
years to retire for each player. If a player has already retired, display as 1 in
the "retired_flag" column. If not yet retired, display 0 in "retired_flag" column?
select player_name,
case when floor(datediff(year, Date_of_Birth, current_date)) >= 40 then 0 else 40 -
floor(datediff(year, Date_of_Birth, current_date) end as Years_to_Retire,
case when floor(datediff(year, current_date, date_of_birth::date)) > 40 then 1 else
0 end as retired_flag from player_info;
--11.From the "team performance" dataset, calculate the match winner by looking at
other fields within that dataset. Compare your results with the "Match_winner"
column to test your accuracy
with cte as (select match_id, match_winner,
case when (fiirst_innings_score > second_innings_score) then split_part(teams, ' '
1) else split_part(teams, ' ' 2) end as calculated_winner
from team_performance)
select match_id, match_winner, calculated_winner,
case when (calculated_winner = match_winner) then 'results match' else 'results do
not match' end as Accuracy from cte;