简体   繁体   English

MySql - 将ALIAS用于​​多个列

[英]MySql - use of ALIAS for multiple columns

I saw the following code: 我看到了以下代码:

SELECT 
    u.ID, u.username, u.active, u.email, u.admin, u.banned, 
    u.name AS groupmemberships 
FROM users u 
WHERE u.ID={$uid}

and was wondering where the official documentation about aliasing multiple columns was. 并想知道关于多列混叠的官方文档在哪里。 W3schools (not the best source) as the only place where I found "documentation" in the following way: W3schools(不是最好的来源)是我通过以下方式找到“文档”的唯一地方:

SELECT column_name(s) FROM table_name AS alias_name;

http://www.w3schools.com/sql/sql_alias.asp http://www.w3schools.com/sql/sql_alias.asp

I would appreciate a link to official documentation so I can look it over. 我希望获得官方文档的链接,以便我可以查看。

You can't use the same alias for multiple columns, but you can concatenate values and give the result an alias: 您不能对多个列使用相同的别名,但您可以连接值并为结果指定别名:

SELECT 
  u.ID, u.username, u.active, u.email, u.admin, u.banned, 
  u.name + u.username AS groupmemberships 
FROM users u 

If this is what you want, then check here for how to deal with null values. 如果这是你想要的,那么请在这里检查如何处理空值。

您可以使用concat函数为多列获取单个别名,

 select concat(first_name, ' ', last_name) as employee_name from user;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM