日期:2014-05-17 浏览次数:20515 次
SELECT AdvanceNum,DeliveryListNum,Consignor,DeclareDate,Declare_Name,bbd.BusinessNum
,Flag_Customs ,IsExists--表示 是否 存在费用
(SELECT AdvanceNum,DeliveryListNum,Consignor,DeclareDate,Declare_Name,bbd.BusinessNum
,Flag_Customs
from customs_CustomsDeclaration as ccd ,bus_BusinessDetail as bbd
where bbd.BusinessNum = ccd.BusinessNum and bbd.BusinessNum in
( select BusinessNum from (select b.BusinessNum,count(*) as totalNum,
SUM(case when f.Flag_ManagerCheckCost= '0' then 1 else 0 end)
as checkNum
from bus_BusinessDetail b inner join cost_FeeInfo f on b.BusinessNum=f.BusinessNum
group by b.BusinessNum ) t
where totalNum>0 and checkNum > 0
UNION
SELECT BusinessNum FROM customs_CustomsDeclaration
WHERE BusinessNum NOT IN ( SELECT BusinessNum FROM cost_FeeInfo )
and InputDate BETWEEN '2013-10-23 00:00:00' AND '2013-10-30 00:00:00' group by BusinessNum )
AND ccd.InputDate BETWEEN '2013-10-23 00:00:00' AND '2013-10-30 00:00:00' AND ccd.IsAvailable = '1'
group by AdvanceNum,DeliveryListNum,Consignor,DeclareDate,Declare_Name,bbd.BusinessNum,Flag_Customs)