Identify MVP Recipient in Game

MySQLMySQLBeginner
Practice Now

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.

  1. Open a terminal and start the MySQL service:
sudo service mysql start
  1. Access MySQL using the sudo command without any password:
sudo mysql
  1. In the MySQL client, run the following command to create the basketball database:
CREATE DATABASE basketball;
  1. Navigate to the basketball database:
USE basketball;
  1. Create the mvp_votes table:
CREATE TABLE mvp_votes (
  player VARCHAR(50),
  votes INT
);
  1. Insert the provided data into the mvp_votes table:
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.

  1. Open a text editor and create a new file named MVP.sql in the /home/labex/project directory.
  2. In the MVP.sql file, 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.

  1. Save the MVP.sql file.

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.

  1. In the MySQL client, run the following command to execute the MVP.sql script:
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.

âœĻ Check Solution and Practice

Summary

Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.

Other MySQL Tutorials you may like