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

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) mysql(("`MySQL`")) -.-> mysql/DatabaseFunctionsandDataTypesGroup(["`Database Functions and Data Types`"]) sql(("`SQL`")) -.-> sql/BasicSQLCommandsGroup(["`Basic SQL Commands`"]) sql(("`SQL`")) -.-> sql/DataManipulationandQueryingGroup(["`Data Manipulation and Querying`"]) sql(("`SQL`")) -.-> sql/DataDefinitionandIntegrityGroup(["`Data Definition and Integrity`"]) sql(("`SQL`")) -.-> sql/DatabaseManagementandOptimizationGroup(["`Database Management and Optimization`"]) mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") mysql/DatabaseFunctionsandDataTypesGroup -.-> mysql/database("`DB Function - Info Retrieval`") sql/BasicSQLCommandsGroup -.-> sql/select("`SELECT statements`") sql/DataManipulationandQueryingGroup -.-> sql/where("`WHERE clause`") sql/DataManipulationandQueryingGroup -.-> sql/in("`IN clause`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/insert("`Data Insertion`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/create_table("`Table Creation`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/use_database("`Database Selection`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/create_database("`Database Creation`") sql/BasicSQLCommandsGroup -.-> sql/insert("`INSERT INTO statements`") sql/BasicSQLCommandsGroup -.-> sql/create_table("`CREATE TABLE statements`") sql/DataDefinitionandIntegrityGroup -.-> sql/data_types("`Data Types`") sql/DatabaseManagementandOptimizationGroup -.-> sql/using_indexes("`Using Indexes`") subgraph Lab Skills mysql/source -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} mysql/database -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/select -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/where -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/in -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} mysql/select -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} mysql/insert -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} mysql/create_table -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} mysql/use_database -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} mysql/create_database -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/insert -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/create_table -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/data_types -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} sql/using_indexes -.-> lab-301346{{"`Identify MVP Recipient in Game`"}} end

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.

Summary

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

Other MySQL Tutorials you may like