如何从MySQL表返回列的值作为一组值?
借助MySQL MAKE_SET()函数,我们可以将MySQL表中的列值作为一组值返回。为了理解它,我们以带有以下数据的Student_Name表为例-
mysql> Select * from Student_Name;+---------+-------+---------+
| FName | Mname | Lname |
+---------+-------+---------+
| Rahul | NULL | Singh |
| Gaurav | Kumar | NULL |
| Harshit | NULL | Khurana |
| Yash | Pal | Sharma |
+---------+-------+---------+
4 rows in set (0.00 sec)
现在,假设我们要设置“ Fname”和“ Lname”列的值,则下面的查询可以做到这一点-
mysql> Select MAKE_SET(1|4,fname,mname,lname)AS '(Fname,Lname)' from Student_name;+-----------------+
| (Fname,Lname) |
+-----------------+
| Rahul,Singh |
| Gaurav |
| Harshit,Khurana |
| Yash,Sharma |
+-----------------+
4 rows in set (0.00 sec)
以上是 如何从MySQL表返回列的值作为一组值? 的全部内容, 来源链接: utcz.com/z/353481.html