当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL Aliases

SQL
SQL Create View
SQL Server
SQL 速查
SQL 摘要
MYSQL 列类型存储需求

SQL Aliases


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 784 ::
收藏到网摘: n/a

With SQL, aliases can be used for column names and table names.
通过SQL语句,可以将返回结果的栏目名或是表名重命名


Column Name Alias
栏目名转换

语法:

SELECT column AS column_alias FROM table


Table Name Alias
表格名转换

语法:

SELECT column FROM table AS table_alias


Example: Using a Column Alias
举例:使用栏目转换

Person数据表:

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger

SQL语句为:

SELECT LastName AS Family, FirstName AS Name
FROM Persons

返回的结果为:

Family Name
Hansen Ola
Svendson Tove
Pettersen Kari


Example: Using a Table Alias
举例:使用表名转换

Person数据表:

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger

SQL语句:

SELECT LastName, FirstName
FROM Persons AS Employees

返回的结果为:

表名换成了Employees:

LastName FirstName
Hansen Ola
Svendson Tove
Pettersen Kari

评论 (0) All

登陆 | 还没注册?