为了合并两个或更多列的值,我们可以使用MySQLCONCAT()
函数。在这种情况下,CONCAT()
函数的参数将是列的名称。例如,假设我们有一个名为“ Student”的表,并且我们希望将学生的姓名和地址集中在一栏中,那么可以编写以下查询:
mysql> Select Id, Name, Address, CONCAT(ID,', ',Name,', ', Address)AS 'ID, Name,Address' from Student; +------+---------+---------+--------------------+ | Id | Name | Address | ID, Name, Address | +------+---------+---------+--------------------+ | 1 | Gaurav | Delhi | 1, Gaurav, Delhi | | 2 | Aarav | Mumbai | 2, Aarav, Mumbai | | 15 | Harshit | Delhi | 15, Harshit, Delhi | | 20 | Gaurav | Jaipur | 20, Gaurav, Jaipur | +------+---------+---------+--------------------+ 4 rows in set (0.00 sec)