0
点赞
收藏
分享

微信扫一扫

MySQL数据库查询数据操作篇第二十四为表和字段取别名

大柚子top 2022-05-20 阅读 40


24.为表和字段取别名

为表取别名
mysql> select * from orders as o
-> where o.o_num = 3001;
+-------+---------------------+------+
| o_num | o_date | c_id |
+-------+---------------------+------+
| 3001 | 2019-12-11 00:00:00 | 1001 |
+-------+---------------------+------+
1 row in set

mysql> select c.c_id,o.o_num
-> from customers as c left outer join orders as o
-> on c.c_id = o.c_id;
+-------+-------+
| c_id | o_num |
+-------+-------+
| 10086 | NULL |
| 10087 | NULL |
| 10088 | NULL |
+-------+-------+
3 rows in set

mysql> select f1.f_id,f1.f_name
-> from fruits as f1,fruits as f2
-> where f1.s_id = f2.s_id and f2.f_id = "a1";
+------+--------+
| f_id | f_name |
+------+--------+
| a1 | apple |
+------+--------+
1 row in set

为字段取别名:
mysql> select f1.f_name as fruit_name,f1.f_price as fruit_price
-> from fruits as f1
-> where f1.f_price < 8;
+------------+-------------+
| fruit_name | fruit_price |
+------------+-------------+
| apple | 5.2 |
| banana | 6.2 |
| caomei | 7.2 |
+------------+-------------+
3 rows in set



举报

相关推荐

0 条评论