版权声明:如若转载,请联系作者。 https://blog.csdn.net/liu16659/article/details/82794517
Mysql 中对别名的操作
0.背景
- 查看测试表的数据
mysql> select * from customers;
+-------------+----------+
| customer_id | city |
+-------------+----------+
| 163 | hangzhou |
| 9you | shanghai |
| alibaba | hangzhou |
| netease | hangzhou |
| 163 | beijing |
| alibaba | shanghai |
| 163 | beijing |
+-------------+----------+
7 rows in set (0.00 sec)
- 别名在
group
语法中使用**[报错]**
mysql> select
-> customer_id as id
-> from customers
-> group id;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id' at line 4
- 别名在
order by
语法中使用**[正常]**
mysql> select
-> customer_id as id
-> from customers
-> order by id;
+---------+
| id |
+---------+
| 163 |
| 163 |
| 163 |
| 9you |
| alibaba |
| alibaba |
| netease |
+---------+
7 rows in set (0.00 sec)