0% found this document useful (0 votes)
10 views4 pages

SQL Queries for Player Data Analysis

The document contains a series of SQL queries aimed at analyzing player data from a dataset named 'players_data'. Key queries include counting total players and nationalities, calculating total wages, identifying players with the highest and lowest wages, and determining the distribution of players by preferred foot and jersey number. Additionally, it explores player join dates and club performance metrics.

Uploaded by

qwertyreddyb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

SQL Queries for Player Data Analysis

The document contains a series of SQL queries aimed at analyzing player data from a dataset named 'players_data'. Key queries include counting total players and nationalities, calculating total wages, identifying players with the highest and lowest wages, and determining the distribution of players by preferred foot and jersey number. Additionally, it explores player join dates and club performance metrics.

Uploaded by

qwertyreddyb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SQL Assignment

select * from players_data;


select count(*) from players_data;
#How many players are there in the dataset?
SELECT COUNT(*) AS total_players
FROM players_data;
#How many nationalities do these players belong to?
SELECT COUNT(DISTINCT Nationality) AS total_nationalities
FROM players_data;
#What is the total wage given to all players? What's the average and standard
deviation?
select sum(wage)as total_wages,avg(wage) as avg_wages,stddev(wage) as
std_wages from players_data;
##----Which nationality has the highest number of players, what are the top 3
nationalities by # of players?
select nationality,count(*) as player_count from players_data
group by Nationality
order by player_count desc
limit 3;
# #-----Which player has the highest wage? Who has the lowest?-----#
select * from players_data limit 10;
select name,wage
from players_data
where wage=(select max(Wage) from players_data);
select name,wage
from players_data
where wage=(select min(wage) from players_data);
##-----The player having the – best overall rating? Worst overall rating?-----#
select name,Potential
from players_data
where potential=(select max(Potential) from players_data);
select name,Potential
from players_data
where potential=(select min(Potential) from players_data);
##-----Club having the highest total of overall rating? Highest Average of overall
rating?-----#
select club,avg(overall)as avg_overall
from players_data
where club is not null
group by club
#-----What are the top 5 clubs based on the average ratings of their players
and their corresponding averages?-----#
select name,club,avg(potential) as avg_potential
from players_data
where club is not null
group by club,Name
order by avg_potential desc
limit 5;
#-----What is the distribution of players whose preferred foot is left vs right?-----#
select * from players_data limit 10;
select preferred_foot,count(*) as cnt_pref from players_data
group by preferred_foot;
#-----Which jersey number is the luckiest?-----#
select jersey_number,avg(overall) avg_overall_potential,count(*) as cnt_palyers
from players_data
where jersey_number is not null
group by Jersey_Number
order by avg_overall_potential desc
limit 1;
#-----What is the frequency distribution of nationalities among players whose
club name starts with M?-----#
SELECT Nationality, COUNT(*) AS player_count
FROM players_data
WHERE Club LIKE 'M%'
GROUP BY Nationality
ORDER BY player_count DESC;
#-----How many players have joined their respective clubs in the date range 20
May 2018 to 10 April 2019 (both inclusive)?------#

SELECT COUNT(*) AS player_count


FROM players_data
WHERE STR_TO_DATE(Joined, '%d-%m-%Y')
BETWEEN '2018-05-20' AND '2019-04-10';
#-----How many players have joined their respective clubs date wise?-----#
SELECT
STR_TO_DATE(Joined, '%d-%m-%Y') AS join_date,
COUNT(*) AS player_count
FROM
players_data
WHERE
Joined IS NOT NULL
GROUP BY
STR_TO_DATE(Joined, '%d-%m-%Y')
ORDER BY
join_date;
#-----How many players have joined their respective clubs yearly?-----#
SELECT
YEAR(STR_TO_DATE(Joined, '%d-%m-%Y')) AS join_year,
COUNT(*) AS player_count
FROM
players_data
WHERE
Joined IS NOT NULL
GROUP BY
join_year
ORDER BY
join_year;

You might also like