Introduction
In this project, you will learn how to identify the Most Valuable Player (MVP) recipient in a basketball game using SQL queries. You will create a database, set up a table, and write an SQL statement to determine the player who received the most votes and is awarded the MVP honor.
👀 Preview
MariaDB [(none)]> SOURCE /home/labex/project/MVP.sql;
+-----------+
| MVP |
+-----------+
| WestBrook |
+-----------+
1 row in set (0.000 sec)
🎯 Tasks
In this project, you will learn:
- How to create a database and table in MySQL
- How to insert data into the table
- How to write an SQL statement to compare and determine the MVP recipient
🏆 Achievements
After completing this project, you will be able to:
- Understand how to set up a database and table in MySQL
- Write SQL statements to query and manipulate data
- Determine the MVP recipient based on voting results
Set Up the Database and Table
In this step, you will learn how to set up the database and table required for the project.
- Open a terminal and start the MySQL service:
sudo service mysql start
- Access MySQL using the
sudocommand without any password:
sudo mysql
- In the MySQL client, run the following command to create the
basketballdatabase:
CREATE DATABASE basketball;
- Navigate to the
basketballdatabase:
USE basketball;
- Create the
mvp_votestable:
CREATE TABLE mvp_votes (
player VARCHAR(50),
votes INT
);
- Insert the provided data into the
mvp_votestable:
INSERT INTO mvp_votes (player, votes) VALUES
('WestBrook', 888),
('Harden', 753);
Now, you have set up the database and table required for the project.
Determine the MVP Recipient
In this step, you will write an SQL statement to determine which of the two players, WestBrook or Harden, will receive the MVP honor.
- Open a text editor and create a new file named
MVP.sqlin the/home/labex/projectdirectory. - In the
MVP.sqlfile, write the following SQL statement:
SELECT IF(
(SELECT votes FROM mvp_votes WHERE player = 'WestBrook') >
(SELECT votes FROM mvp_votes WHERE player = 'Harden'), 'WestBrook', 'Harden') AS MVP;
This statement uses the IF function to compare the number of votes for WestBrook and Harden, and returns the name of the player who received the most votes as the MVP.
- Save the
MVP.sqlfile.
Now, you have written the SQL statement to determine the MVP recipient.
Run the Script
In this step, you will run the MVP.sql script in the MySQL client to see the result.
- In the MySQL client, run the following command to execute the
MVP.sqlscript:
MariaDB [basketball]> SOURCE /home/labex/project/MVP.sql;
The output should be:
+-----------+
| MVP |
+-----------+
| WestBrook |
+-----------+
1 row in set (0.000 sec)
This output shows that WestBrook is the recipient of the MVP award.
Congratulations! You have successfully completed the project to identify the MVP recipient in the game.
Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



