SQL 查询 空表,用于计算
DUAL 是一个特殊的虚拟表名,可以在不需要从真实表中提取数据时使用。
mysql> select (select capacity from capacity where date=DATE_SUB(CURDATE(), INTERVAL 1 DAY) ) - (select capacity from capacity where date=DATE_SUB(CURDATE(), INTERVAL 2 DAY)) as IncrementPerDay from DUAL;
+-----------------+
| IncrementPerDay |
+-----------------+
| 10 |
+-----------------+
1 row in set (0.00 sec)
mysql> select (select capacity from capacity where date=DATE_SUB(CURDATE(), INTERVAL 1 DAY) ) - (select capacity from capacity where date=DATE_SUB(CURDATE(), INTERVAL 2 DAY)) as IncrementPerDay;
+-----------------+
| IncrementPerDay |
+-----------------+
| 10 |
+-----------------+
1 row in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
reference
- [1] TencentCloud. 如何使SQL INSERT SELECT查询在空表上工作?open in new window