我正试着想出一个工作日内有多少次送货被休了。注意:我不能定义函数。
我有一张table,上面有送货细节,比如:
+--------+---------------+---------------+
| Rec_Id | Date_Received | Date_Promised |
+--------+---------------+---------------+
| 1 | 2020-07-01 | 2020-07-07 |
+--------+---------------+---------------+
| 2 | 2020-07-15 | 2020-07-08 |
+--------+---------------+---------------+
我有一个工作日表如下(t表示这是一个工作日):
+---------------+----------+
| CALENDAR_DATE | WORK_DAY |
+---------------+----------+
| 2020-07-01 | T |
+---------------+----------+
| 2020-07-02 | F |
+---------------+----------+
| 2020-07-03 | F |
+---------------+----------+
| 2020-07-04 | F |
+---------------+----------+
| 2020-07-05 | F |
+---------------+----------+
| 2020-07-06 | F |
+---------------+----------+
| 2020-07-07 | T |
+---------------+----------+
| 2020-07-08 | T |
+---------------+----------+
| 2020-07-09 | T |
+---------------+----------+
| 2020-07-10 | T |
+---------------+----------+
| 2020-07-11 | F |
+---------------+----------+
| 2020-07-12 | F |
+---------------+----------+
| 2020-07-13 | T |
+---------------+----------+
| 2020-07-14 | T |
+---------------+----------+
| 2020-07-15 | T |
+---------------+----------+
结果如下:
+--------+---------------+---------------+----------+
| Rec_Id | Date_Received | Date_Promised | Days_Off |
+--------+---------------+---------------+----------+
| 1 | 2020-07-01 | 2020-07-07 | -1 |
+--------+---------------+---------------+----------+
| 2 | 2020-07-15 | 2020-07-08 | 5 |
+--------+---------------+---------------+----------+
提前谢谢
1条答案
按热度按时间hgtggwj01#
您可以使用横向联接、子查询和条件逻辑:
您可以在子查询中移动条件逻辑,以稍微缩短代码—尽管我怀疑这可能会降低效率: