- 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
Find percentage from marks in MySQL
Let us first create a −
mysql> create table DemoTable1398 -> ( -> Marks int -> ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1398 values(78); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1398 values(82); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1398 values(90); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1398 values(98); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select −
mysql> select * from DemoTable1398;
This will produce the following output −
+-------+ | Marks | +-------+ | 78 | | 82 | | 90 | | 98 | +-------+ 4 rows in set (0.00 sec)
Following is the query to find percentage of marks −
mysql> select concat(sum(Marks)/count(*),'%') from DemoTable1398;
This will produce the following output −
+---------------------------------+ | concat(sum(Marks)/count(*),'%') | +---------------------------------+ | 87.0000% | +---------------------------------+ 1 row in set (0.00 sec)
Advertisements