
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Calculating power of a number in MySQL?
To calculate power of a number, use POWER() function. Let us first create a table −
mysql> create table DemoTable ( Amount int ); Query OK, 0 rows affected (0.89 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(64); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(144); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(400); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Amount | +--------+ | 64 | | 144 | | 400 | +--------+ 3 rows in set (0.00 sec)
Following is the query to calculate power of a number −
mysql− select Amount,power(Amount,2) AS CURRENT_AMOUNT from DemoTable;
This will produce the following output −
+--------+----------------+ | Amount | CURRENT_AMOUNT | +--------+----------------+ | 64 | 4096 | | 144 | 20736 | | 400 | 160000 | +--------+----------------+ 3 rows in set (0.04 sec)
- Related Articles
- In MySQL, how to raise a number to the power of another number?
- Calculating a number from its factorial in JavaScript
- To return value of a number raised to the power of another number, we should use ^ operator in MySQL?
- Check if a number is a power of another number in C++
- Calculating byte values to megabyte (MB) in MySQL?
- Calculating percentage in a MySQL query and round off the result
- Nearest power 2 of a number - JavaScript
- How to find power of a number in Python?
- Find power of a number using recursion in C#
- Calculate the Power of a Number in Java Program
- Power of a prime number r in n! in C++
- Check if given number is a power of d where d is a power of 2 in Python
- C++ Program to Calculate Power of a Number
- Calculating h index of a citation in JavaScript
- Calculating the weight of a string in JavaScript

Advertisements