当前位置:网站首页>Query advanced alias
Query advanced alias
2022-07-26 11:33:00 【Hua Weiyun】
13.8 Use alias to query data
MySQL It supports specifying aliases for field names or table names when querying data , When specifying aliases, you can use AS keyword , You can also not use .
13.8.1 Specify an alias for the field name
The syntax format of specifying an alias for a field name is as follows :
SELECT column1 [AS] col1 [, column2 [AS] col2, … , columnn [AS] coln] FROM table_nameamong ,AS Keywords can be omitted .
Inquire about t_goods In the data table t_category_id and t_category Field data .
mysql> SELECT t_category_id categoryId, t_category AS categoryName FROM t_goods;+---------------+----------------+| t_categoryId | categoryName |+---------------+----------------+| 1 | Women's wear / Women's Boutique || 1 | Women's wear / Women's Boutique || 1 | Women's wear / Women's Boutique || 1 | Women's wear / Women's Boutique || 1 | Women's wear / Women's Boutique || 1 | Women's wear / Women's Boutique || 2 | Outdoor sports || 2 | Outdoor sports || 2 | Outdoor sports || 2 | Outdoor sports || 2 | Outdoor sports || 2 | Outdoor sports |+---------------+----------------+12 rows in set (0.00 sec)The result shows that the data is correctly queried . thus it can be seen , Use AS Keywords and not used AS Keywords can specify aliases for fields . When specifying an alias for a field , The field names in the query result data list show aliases ; Otherwise, the field name is displayed .
13.8.2 Specify an alias for the table name
The syntax format of specifying aliases for table names is as follows :
SELECT * FROM table_name [AS] tableNameperhaps
SELECT column1 [, column2, … , columnn] FROM table_name [AS] tableNameamong ,AS Keywords can be omitted .
Query by specifying an alias for the data table t_goods In the data table t_name Fields and t_stock Field data .
mysql> SELECT t_name, t_stock FROM t_goods goods;+--------------+---------+| t_name | t_stock |+--------------+---------+| T T-shirt | 1000 || dress | 2500 || fleece | 1500 || A pair of jeans | 3500 || Pleated skirt | 500 || Woolen coat | 1200 || Bicycle | 1000 || Mountain Bike | 2500 || Alpenstocks | 1500 || Riding equipment | 3500 || Outdoor sports coat | 500 || Skate | 1200 |+--------------+---------+12 rows in set (0.00 sec)13.8.3 Specify aliases for both field names and table names
The syntax format of specifying aliases for both field names and table names is as follows :
SELECT column1 [AS] col1 [, column2 [AS] col2, … , columnn [AS] coln] FROM table_name [AS] tableNameamong ,AS Keywords can be omitted .
Inquire about t_goods In the data table t_name Field 、t_price Fields and t_upper_time Field data .
mysql> SELECT -> t_name name, t_price AS price, t_upper_time upperTime -> FROM t_goods AS goods;+-------------+---------+---------------------+| name | price | uppertime |+-------------+---------+---------------------+| T T-shirt | 39.90 | 2020-11-10 00:00:00 || dress | 79.90 | 2020-11-10 00:00:00 || fleece | 79.90 | 2020-11-10 00:00:00 || A pair of jeans | 89.90 | 2020-11-10 00:00:00 || Pleated skirt | 29.90 | 2020-11-10 00:00:00 || Woolen coat | 399.90 | 2020-11-10 00:00:00 || Bicycle | 399.90 | 2020-11-10 00:00:00 || Mountain Bike | 1399.90 | 2020-11-10 00:00:00 || Alpenstocks | 59.90 | 2020-11-10 00:00:00 || Riding equipment | 399.90 | 2020-11-10 00:00:00 || Outdoor sports coat | 799.90 | 2020-11-10 00:00:00 || Skate | 499.90 | 2020-11-10 00:00:00 |+-------------+---------+---------------------+12 rows in set (0.00 sec)Be careful : Specify an alias for a field or table , It is often used in multi table associative queries .
边栏推荐
- 如何配置JdbcRealm数据源呢?
- 打造绿色数据中心,Colt DCS 是认真的!
- Common library installation
- 702马力破百仅4.5秒!最强皮卡来袭,安全、舒适一个不落
- 1837. Sum of digits under k-ary representation
- 数据可视化-《白蛇2:青蛇劫起》(2)
- Record errors encountered by individuals
- Scrapy shell出现的一个错误
- [error reporting] what do you read in the log
- How to configure the jdbcrealm data source?
猜你喜欢
![36. [difference between const function and function]](/img/14/0f01fdace2ec17e873522cef4ac735.png)
36. [difference between const function and function]

Can SAIC mingjue get out of the haze if its products are unable to sell and decline

找工作4个月,面试15家,终于拿到3个offer,定级P7+

PyQt5快速开发与实战 第1章 认识PyQt5

QT——LCDNumber

Leetcode-209. subarray with the smallest length (binary, prefix and, sliding window)

【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)

Pyqt5 rapid development and practice Chapter 1 understanding pyqt5

swagger2.9.2教程 与swagger3.0.0教程
![[vscode] how to connect to the server remotely](/img/b4/9a80ad995bd589596d8b064215b55a.png)
[vscode] how to connect to the server remotely
随机推荐
承认吧 投新能源就是为了安全感
Data type of SQL Server database
After 4 months of job search and 15 interviews, I finally got 3 offers, ranking P7+
ESP8266-Arduino编程实例-认识ESP8266
配置文件以rc结尾什么意思
程序员成长第二十八篇:管理者如何才能不亲力亲为?
贝尔曼期望方程状严谨证明
【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
五万美元的年薪是如何花光的
[learning progress] may
Caused by: scala.MatchError: None (of class scala.None$)
记录个人遇到的错误
3dunity game project practice - first person shooting game
Common library installation
Pyechart离线部署
36.【const函数放在函数前后的区别】
查询进阶 别名
Back to the top of several options (JS)
Ten year structure five year life-06 impulse to leave
Le audio specification overview