- 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
How do I split a numerical query result in MySQL?
To split a numerical query result, you can use the CONCAT() function in MySQL. Let us first create a table −
mysql> create table DemoTable ( StudentId int ); Query OK, 0 rows affected (0.68 sec)
Now you can insert some records in the table using insert command −
mysql> insert into DemoTable values(2222); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(5555); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(4567); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(8905); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-----------+ | StudentId | +-----------+ | 2222 | | 5555 | | 4567 | | 8905 | +-----------+ 4 rows in set (0.00 sec)
Following is the query to split a numerical query result. Here, we have split the first digit of the value −
mysql> select concat(left(StudentId, 1), '/',right(StudentId, length(StudentId)-1)) splitNumericalValue from DemoTable;
Output
+---------------------+ | splitNumericalValue | +---------------------+ | 2/222 | | 5/555 | | 4/567 | | 8/905 | +---------------------+ 4 rows in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google