0
点赞
收藏
分享

微信扫一扫

Mysql 中对别名的操作

生态人 2022-01-28 阅读 75


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)



举报

相关推荐

0 条评论