MySql-将ALIAS用于​​多列 [英] MySql - use of ALIAS for multiple columns

查看:73
本文介绍了MySql-将ALIAS用于​​多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了以下代码:

  SELECT 
u.ID,u.username,u.active, u.email,u.admin,u.banned,
u.name AS组成员身份
来自用户u
WHERE u.ID = {$ uid}

,并且想知道有关别名多列的官方文档在哪里。 W3schools(不是最佳来源)是我通过以下方式找到文档的唯一地方:

  SELECT column_name(s )FROM table_name AS alias_name; 

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



我希望收到指向官方文档的链接,所以我可以查看一下。

解决方案

您不能对多个列使用相同的别名,但可以将值连接起来并给结果别名:

  SELECT 
u.ID,u.username,u.active,u.email,u .admin,u.banned,
u.name + u.username作为组成员
FROM用户u

如果这是您想要的,请在此处中查看如何处理空值。 p>

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:

SELECT column_name(s) FROM table_name AS alias_name;

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.

这篇关于MySql-将ALIAS用于​​多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆