- 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
Select rows having more than 2 decimal places in MySQL?
To select rows with more than 2 decimal places, use SUBSTR() function from MySQL. Let us first create a table −
mysql> create table selectRows2DecimalPlacesDemo -> ( -> Amount varchar(100) -> ); Query OK, 0 rows affected (0.73 sec)
Following is the query to insert records in the table using insert command −
mysql> insert into selectRows2DecimalPlacesDemo values('234.5678'); Query OK, 1 row affected (0.17 sec) mysql> insert into selectRows2DecimalPlacesDemo values('19.50'); Query OK, 1 row affected (0.19 sec) mysql> insert into selectRows2DecimalPlacesDemo values('23.456'); Query OK, 1 row affected (0.17 sec) mysql> insert into selectRows2DecimalPlacesDemo values('12.123'); Query OK, 1 row affected (0.14 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from selectRows2DecimalPlacesDemo;
This will produce the following output −
+----------+ | Amount | +----------+ | 234.5678 | | 19.50 | | 23.456 | | 12.123 | +----------+ 4 rows in set (0.00 sec)
Here is the query to select rows with more than two decimal places −
mysql> select *from selectRows2DecimalPlacesDemo WHERE LENGTH(SUBSTR(Amount,INSTR(Amount,"."))) >3;
This will produce the following output −
+----------+ | Amount | +----------+ | 234.5678 | | 23.456 | | 12.123 | +----------+ 3 rows in set (0.00 sec)
Advertisements