Wuxu Reform Duration Calculation

MySQLMySQLBeginner
Practice Now

Introduction

In this project, you will learn how to access a MySQL database using the sudo command and write an SQL query to calculate the duration of the Wuxu Reform, also known as the "Hundred Days' Reform".

👀 Preview

MariaDB [(none)]> SOURCE /home/labex/project/wuxu.sql;
+-------------------------+
| Duration of Wuxu Reform |
+-------------------------+
|                     103 |
+-------------------------+
1 row in set (0.000 sec)

ðŸŽŊ Tasks

In this project, you will learn:

  • How to start the MySQL service and access the MySQL database using the sudo command
  • How to write an SQL query to calculate the duration of the Wuxu Reform
  • How to save the SQL query in a script file and execute it in the MySQL prompt

🏆 Achievements

After completing this project, you will be able to:

  • Understand the basics of accessing and interacting with a MySQL database using the command line
  • Write SQL queries to perform simple data analysis tasks
  • Apply your SQL knowledge to solve real-world problems, such as calculating the duration of historical events

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) sql(("`SQL`")) -.-> sql/BasicSQLCommandsGroup(["`Basic SQL Commands`"]) sql(("`SQL`")) -.-> sql/DataManipulationandQueryingGroup(["`Data Manipulation and Querying`"]) sql(("`SQL`")) -.-> sql/AdvancedDataOperationsGroup(["`Advanced Data Operations`"]) mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") sql/BasicSQLCommandsGroup -.-> sql/select("`SELECT statements`") sql/DataManipulationandQueryingGroup -.-> sql/in("`IN clause`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") sql/AdvancedDataOperationsGroup -.-> sql/numeric_functions("`Numeric functions`") sql/AdvancedDataOperationsGroup -.-> sql/date_time_functions("`Date and Time functions`") subgraph Lab Skills mysql/source -.-> lab-301436{{"`Wuxu Reform Duration Calculation`"}} sql/select -.-> lab-301436{{"`Wuxu Reform Duration Calculation`"}} sql/in -.-> lab-301436{{"`Wuxu Reform Duration Calculation`"}} mysql/select -.-> lab-301436{{"`Wuxu Reform Duration Calculation`"}} sql/numeric_functions -.-> lab-301436{{"`Wuxu Reform Duration Calculation`"}} sql/date_time_functions -.-> lab-301436{{"`Wuxu Reform Duration Calculation`"}} end

Access MySQL

In this step, you will learn how to access the MySQL database using the sudo command without any password.

  1. Open a terminal on your system.
  2. Run the following command to start the MySQL service:
sudo service mysql start
  1. Now, run the following command to access the MySQL database:
sudo mysql

You should now be able to access the MySQL database without any password.

Write the SQL Query

In this step, you will write the SQL query to display the duration, in days, of the Wuxu Reform.

  1. Open the wuxu.sql file.
  2. In the wuxu.sql file, add the following SQL query:
SELECT ABS(DATEDIFF('1898-09-21', '1898-06-10')) AS `Duration of Wuxu Reform`;

This query calculates the absolute difference in days between the start date (June 10, 1898) and the end date (September 21, 1898) of the Wuxu Reform, and assigns the result to the field alias "Duration of Wuxu Reform".

Run the SQL Script

In this step, you will run the SQL script you created in the previous step.

  1. In the MySQL prompt, run the following command to execute the wuxu.sql script:
MariaDB [(none)]> SOURCE /home/labex/project/wuxu.sql;

This command will execute the SQL script and display the result.

You should see the following output:

+-------------------------+
| Duration of Wuxu Reform |
+-------------------------+
|                     103 |
+-------------------------+
1 row in set (0.000 sec)

The output shows that the duration of the Wuxu Reform was 103 days.

Congratulations! You have successfully completed the project by writing an SQL query to calculate the duration of the Wuxu Reform.

âœĻ 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