![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements