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

reference

访客IP ,您的网络 访问优先

本站是个人博客,书写大数据、数据科学等领域的原创学习记录,转载请注明出处

本站运行于 腾讯云 腾讯云