# MySQL PI() – Calculating Pi Value in MySQL [Simple Examples] In this tutorial, we will study the MySQL `PI()` function. While studying maths in high school, you must have come across the value of 𝜋 known as Pi. The value of Pi is 22/7 or 3.142 up to three decimal places. Pi is used in a variety of mathematical calculations –  geometry, calculus, and physics.

One of the first instances where you would have encountered Pi is while finding the area of a circle. Since Pi is so widely used in different operations across different domains, MySQL provides us with the `PI()` function which returns the value of Pi.

## Syntax of MySQL PI()

```.wp-block-code {
border: 0;
}

.wp-block-code > span {
display: block;
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}`PI();`Code language: SQL (Structured Query Language) (sql)```

## Examples of MySQL PI()

Let us look at a basic example of printing the value of Pi. We will alias in our `SELECT` statement to make our output readable.

``SELECT PI() AS Value_of_PI;`Code language: SQL (Structured Query Language) (sql)`

And the output we get is the value of 𝜋 up to 6 decimal places.

### Calculating Circumference and Area of a Circle

Let us dive into some complex and real-world examples now. Consider the below ‘Circle’ table.

Let us display figure ID, radius and the circumference of these circles. The formula for the circumference of a circle is 2𝜋r, where r is the radius of the circle. Our query is,

``SELECT FigureId, Radius, 2*PI()*Radius AS Circumference FROM Circle;`Code language: SQL (Structured Query Language) (sql)`

And we get the output as,

Now, how about using the above query but displaying only those circle records whose circumference is greater than 50? We will use the `WHERE` clause.

``SELECT FigureId, Radius, 2*PI()*Radius AS Circumference FROM Circle WHERE 2*PI()*Radius>50;`Code language: SQL (Structured Query Language) (sql)`

And we get our output as,

Let us display the figure id, radius, and the area of these circles. The formula for the area of a circle is 𝜋r2, where r is the radius of the circle. We will use the `POW()` function in this query. Our query is,

``SELECT FigureId, Radius, PI()*POW(Radius, 2) AS Area FROM Circle;`Code language: SQL (Structured Query Language) (sql)`

And we get our output as,

### Calculating Surface Area and Volume of a Sphere

Let us look at another example. Consider the below Sphere table.

Let us create a column named SurfaceArea which contains the surface area value of the corresponding spheres. We will use the `ALTER` and `UPDATE` statements for this. The formula for the surface area of a sphere is 4𝜋r2.

``````ALTER TABLE Sphere ADD SurfaceArea float;
SELECT * FROM Sphere;```Code language: SQL (Structured Query Language) (sql)```

The `ALTER` statement will add the SurfaceArea column with data type float to the Sphere table. The column is pre-populated with NULL values. The `UPDATE` statement will update all the NULL values in the column to the value of the surface area of the sphere. Finally, we use the `SELECT` statement to display our newly updated table.

The output is shown as follows,

Building on the above, let us create a column named Volume which contains the volume value of the corresponding spheres. The formula for the volume of a sphere is 4/3 𝜋r3.

``````ALTER TABLE Sphere ADD Volume float;
SELECT * FROM Sphere;```Code language: SQL (Structured Query Language) (sql)```

Just like the previous example, the `ALTER` statement will add the Volume column with data type float to the Sphere table. The column is pre-populated with NULL values. The `UPDATE` statement will update all the NULL values in the column to the value of the volume of the sphere.

The 4/3, MySQL PI() and `POW()` expressions get evaluated first and then all their results get multiplied. Finally, we use the `SELECT` statement to display our newly updated table. Notice we use the division operator and not the `DIV` function.

And the output is,

## Conclusion

MySQL `PI()` is very useful for operations across various domains and more so while performing operations on a table. I would encourage you to try different use cases or formulas which include Pi and apply them using `PI()` in MySQL.