Tutorialspoint

1 Answer
Ankith Reddy

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

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.