[英]MYSQL: Dynamic columns in mysql --> first, last name to full name:
I was wondering if you have two columns for lets say 我想知道你是否有两栏可以说
first name.
last name.
what you store in the database. 您存储在数据库中的内容。
Can you create a 'dynamic' column 'fullname' in the database that automatically creates the name out of the first and last name? 您可以在数据库中创建“动态”列“全名”,以自动从名字和姓氏中创建名称吗?
firstname |lastname |fullname (this goes automatically)
-----------------------------------------
foo |bar |foo bar
If you just want to select the full name, you can do just that: 如果您只想选择全名,则可以执行以下操作:
select concat(firstname, ' ', lastname) as fullname from users
If you actually want a column (ie be able to perform updates against it), then it's not possible, AFAIK. 如果您确实想要一列(即能够对其进行更新),那么AFAIK是不可能的。
您可以尝试如下操作:
SELECT CONCAT(firstname, ' ', lastname) as firstlast FROM users
此操作还确保不添加任何空格:
SELECT IF(ISNULL(firstname), lastname, CONCAT(firstname, ' ', lastname)) AS fullname FROM users
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.