Open In App

POWER(), SUM() and PI() Function in MariaDB

Improve
Improve
Like Article
Like
Save
Share
Report

1. POWER() Function :
In MariaDB, the POWER() function is used to returns m raised to the nth power. In this function, two parameters will be passed first will be m (Numeric). It is the base used in the calculation, and the second will be n (Numeric). It is the exponent used in the calculation.

Syntax :

POWER(m, n)

Returns : Value of m raised to the nth power.

Table – IPL

Team_id Teamname Score</tdh
1 RR 140
2 CSK 210
3 MI 160
4 DC 170

Example-1 :

SELECT POWER(Score) AS POWER_Score
FROM IPL
WHERE Teamname='CSK';

Output :

POWER_Score
44100


Example-2 :

SELECT (POWER(7, 2) - POWER(2, 4)) AS POWER_VALUE;

Output :

POWER_VALUE
33


Example-3 :

SELECT (POWER(10, 0) * POWER(2, 3)) AS POWER_VALUE;

Output :

POWER_VALUE
8


2. SUM() Function :
In MariaDB, the SUM() function is used to return the summed value of an expression. In this function, aggregate_expression or multiple expressions will be passed, which will return a result. It works like sum function in the processed query. An aggregate_expression will be pass as a parameter and it will return the summed value of the expression. NULL values are ignored.

Syntax :

SELECT SUM(aggregate_expression)
FROM tables
[WHERE conditions];

Returns : The summed value of an expression.

Example-1 :

SELECT SUM(Score) AS TOTAL_Score
FROM IPL;

Output :

TOTAL_Score
680


Example-2 :

SELECT (SUM(Score) + 100) AS TOTAL_Score
FROM IPL
WHERE Score<200;

Output :

TOTAL_Score
570


Example-3 :

SELECT (SUM(Score) * 2) AS TOTAL_Score
FROM IPL
WHERE Score>170;

Output :

TOTAL_Score
340


3. PI() Function :
In MariaDB, the PI() Function used to return the value of π (pi) displayed upto 6 decimal places. In this function, no parameter will be passed and it will return the value of pi. It uses the double-precision value when it will be used in calculations with other double-precision values. It displays value up to only 6 decimal places.

Syntax :

PI( )

Returns : The value of π (pi) upto 6 decimal places.

Example-1 :

SELECT PI();

Output :

3.141593


Example-2 :

SELECT PI()*3.000000000000000;

Output :

9.424777960769380


Example-3 :

SELECT PI()+5;

Output :

 8.141593

Last Updated : 04 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads