Introduction
In this project, you will learn how to obtain the value of Pi rounded to two decimal places using an SQL statement in the MySQL client.
👀 Preview
MariaDB [(none)]> SOURCE /home/labex/project/getPi.sql;
+------+
| Pi |
+------+
| 3.14 |
+------+
1 row in set (0.000 sec)
🎯 Tasks
In this project, you will learn:
- How to start the MySQL server using the
sudocommand - How to create an SQL script to display the value of Pi rounded to two decimal places
- How to execute the SQL script in the MySQL client
🏆 Achievements
After completing this project, you will be able to:
- Understand how to use the
PI()function in MySQL to retrieve the value of Pi - Use the
ROUND()function to round the value of Pi to a specific number of decimal places - Create and execute SQL scripts in the MySQL client
Start MySQL and Create the SQL Script
In this step, you will learn how to start the MySQL server and create the SQL script to display the value of Pi rounded to two decimal places.
- Open a terminal and start the MySQL server using the
sudocommand, which will not require a password:
sudo service mysql start
- Open the MySQL client by running the following command:
sudo mysql
- Open the
getPi.sqlfile, add the following SQL query:
SELECT ROUND(PI(), 2) AS Pi;
This query uses the ROUND() function to round the value of PI() to two decimal places and assigns the result to the alias Pi.
Execute the SQL Script
In this step, you will learn how to execute the SQL script you created in the previous step.
- In the MySQL client, execute the SQL script by running the following command:
SOURCE /home/labex/project/getPi.sql;
This command will execute the SQL script and display the value of Pi rounded to two decimal places.
You should see the following output:
+------+
| Pi |
+------+
| 3.14 |
+------+
1 row in set (0.000 sec)
The output shows the value of Pi rounded to two decimal places, as specified in the SQL query.
Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



