SQL Alias 别名

SQL 别名(Alias)是用于组织输出,使得它更易读和更有含义。SQL别名(Alias)可以用于表名,也可以用于列名。

SQL 别名(Alias) 语法

SELECT T.Column1 AS c1, T.Column2 AS c2, T.Column3 AS c3, ...
FROM TABLE1
AS T

SQL 别名(Alias) 范例

数据表: Employees

EmployeeId FirstName LastName Department Salary
203 Marfg Fxun Finance 78000
204 Joznk Llnyo Finance 45800
205 Hasuu Kynuoo Finance 57000
206 Jkucc Qihha Finance 62000
302 Biee Uioooi Development 75000
303 Kmoao Astuu Development 55000
304 Pissue Koooi Development 49000

选择所有职员(Employee)的人数:

SELECT COUNT(E.EmployeeId) AS totalEmployees
FROM Employees AS E

结果会类似于:

totalEmployees
7

4 Responses to SQL Alias 别名

  1. The tutorial for Sql Alias is honestly good. The functions seems to be useful in a situation when you want to organize the output. Isn’t it work as Vlookup in excel?

  2. Alias is useful only if you’re dealing with complex queries involving multiple tables; specially if you run the risk of 2 different tables having the same or similar field names.

  3. Massimo Bizzarro says:

    I need to do something like:

    Set AliasName for dbo.RealName

    so sql query like
    select * from AliasName.dbo.MyTable
    will work

    I think many people need to do it

    Thank you
    Massimo Bizzarro

  4. I think it is the best website about sql. I am creating MySql database on my website and every tutorial from that page helps me a lot.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled