计算表中存在但不存在于另一个表中的总行数

时间:2017-03-05 05:55:40

标签: mysql sql

我有这三个表:

预订

    AWBNO       BYHUB         ENTRYDATE
     111         HO            2017-02-02
     222         HO            2017-02-02
     333         HO            2017-02-02
     444         HO            2017-02-02
     555         HO            2017-02-02

接收

   AWBNO        FROMHUB         ENTRYDATE
   111            AP             2017-02-04
   222            AP             2017-02-04
   333            AP             2017-02-04

状态

   AWBNO       TOHUB          STATUS             ENTRYDATE     
    111         HO            DELIVERD           2017-02-05
    222         HO            DELIVERD           2017-02-05
    333         HO            DELIVERD           2017-02-05
    444         HO            DELIVERD           2017-02-05
    555         HO            DELIVERD           2017-02-05 

我想计算AWBNO表格中不存在但Receiving表格中存在但已存在的总Booking
我喜欢这种格式的输出:

输出

 TOTAL_BOOKING       TOTAL_RECEVING        TOTAL_RECEVING_FAIL      TOTAL_STATUS      TOTAL_STATUS_DELIVERD_WITHOUT_RECEVING
     5                    3                      2                      5                          2

1 个答案:

答案 0 :(得分:0)

此查询以正确的方式工作,但当我使用拥抱(大数据)数据时,则需要更多时间。

请以其他方式推荐我

 Select count(B.awbno) TOTAL_BOOKING,

 count(R.awbno) TOTAL_RECEIVING,

 count(S.awbno) total_status,

 count(B.awbno) - count(R.awbno) total_receiving_fail,

 count(case when S.status='deliverd' and R.awbno is null then 1 end) TOTAL_STATUS_DELIVERD_WITHOUT_RECEVING

from booking B left join report R on B.awbno = R.awbno

left join status S on B.awbno = S.awbno