当前位置:网站首页>MySQL教程68-AS 设置别名
MySQL教程68-AS 设置别名
2022-07-25 15:35:00 【51CTO】
为了查询方便, MySQL 提供了 AS 关键字来为表和字段指定别名。本节主要讲解如何为表和字段指定一个别名。
为表指定别名
当表名很长或者执行一些特殊查询的时候,为了方便操作,可以为表指定一个别名,用这个别名代替表原来的名称。
为表指定别名的基本语法格式为:
其中各子句的含义如下:
-
<表名>:数据库中存储的数据表的名称。 -
<别名>:查询时指定的表的新名称。 -
AS关键字可以省略,省略后需要将表名和别名用空格隔开。
注意:表的别名不能与该数据库的其它表同名。字段的别名不能与该表的其它字段同名。在条件表达式中不能使用字段的别名,否则会出现“ERROR 1054 (42S22): Unknown column”这样的错误提示信息。
例 1
下面为 tb_students_info 表指定别名 stu,SQL 语句和运行结果如下。
为字段指定别名
在使用 SELECT 语句查询数据时,MySQL 会显示每个 SELECT 后面指定输出的字段。有时为了显示结果更加直观,我们可以为字段指定一个别名。
为字段指定别名的基本语法格式为:
其中,各子句的语法含义如下:
-
<字段名>:为数据表中字段定义的名称。 -
<字段别名>:字段新的名称。 -
AS关键字可以省略,省略后需要将字段名和别名用空格隔开。
例 2
查询 tb_students_info 表,为 name 指定别名 student_name,为 age 指定别名 student_age,SQL 语句和运行结果如下。
边栏推荐
- CF750F1-思维dp
- Binary complement
- LeetCode - 641 设计循环双端队列(设计)*
- CF888G-巧妙字典树+暴力分治(异或最小生成树)
- Copy a word style template to another document
- Pytoch learning notes -- Summary of common functions of pytoch 1
- Flex layout
- Redis distributed lock, it's really impossible without it
- 谷歌博客:采用多重游戏决策Transformer训练通用智能体
- Leetcode - 380 o (1) time to insert, delete and get random elements (design hash table + array)
猜你喜欢

Leetcode - 232 realize queue with stack (design double stack to realize queue)

Pytoch learning notes - Teacher Liu Er RNN advanced chapter - code comments and results

LeetCode - 362 敲击计数器(设计)

LeetCode - 677 键值映射(设计)*

Pytoch learning notes advanced_ CNN (using perception_module) implements MNIST dataset classification - (comments and results)

Activity review | July 6 Anyuan AI X machine heart series lecture No. 2 | MIT professor Max tegmark shares "symbiotic evolution of human and AI"

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

Pytoch learning notes -- Summary of common functions of pytoch 1
SQL cultivation manual from scratch - practical part

Pytorch学习笔记--常用函数总结3
随机推荐
2022-07-25日报:微软提出CodeT:代码生成新SOTA,20个点的性能提升
如何解决跨域问题
Pytoch learning notes advanced_ CNN (using perception_module) implements MNIST dataset classification - (comments and results)
Take you to learn more about JS basic grammar (recommended Collection)
Redis distributed lock, it's really impossible without it
CVPR 2022 | in depth study of batch normalized estimation offset in network
2019 Shaanxi provincial competition j-bit operation + greed
Box avoiding mouse
Binary complement
Pat grade a 1151 LCA in a binary tree (30 points)
Games101 review: Transformation
BSC smart chain contract mode system development details
Window system black window redis error 20creating server TCP listening socket *: 6379: listen: unknown error19-07-28
Wechat applet
Componentization and modularization
JVM knowledge brain map sharing
Understand "average load"
Leetcode - 362 knock counter (Design)
The difference between VaR, let and Const
LeetCode - 622 设计循环队列 (设计)