select、from、dual、as、where
# select、from、dual、as
# select
、from
前面学过的两个最基础的查询语句:
select * from <TableName>;
select <FieldName1>, <FieldName2>[, ... ] from <TableName>;
1
2
3
2
3
你一定想不到还可以这样用:
mysql> select "Fuck you PPT!";
+---------------+
| Fuck you PPT! |
+---------------+
| Fuck you PPT! |
+---------------+
mysql> select 2*7;
+-----+
| 2*7 |
+-----+
| 14 |
+-----+
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 笛卡尔积?
select * from <TableName1>, <TableName2>;
1
from多个表。
# dual
为什么还可以查不存在表的数据?
伪表,“当你查询一个不存在的数据时,假装你有这个表,避免让你尴尬。”,但数据库里根本找不到这个表。
其实 select "Fuck you PPT!";
和 select 2*7
的全写为:
select "Fuck you PPT!" from dual;
select 2*7 from dual;
1
2
3
2
3
# as
指定字段别名。
mysql> select "Fuck you PPT!" as qnmd;
+---------------+
| qnmd |
+---------------+
| Fuck you PPT! |
+---------------+
mysql> select 2*7 as multiply from dual;
+----------+
| multiply |
+----------+
| 14 |
+----------+
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15