sql

select
tb.isPRproject,
if(b.HasYes  is null,0,b.HasYes) as  HasYes,
a.HasNo,
case
when d.name='单一采购'
then '单一采购' when d.name='邀请招标'
then '邀请招标'
when d.name='快速采购'
then '快速采购(5-50万)' end
as proMethod,
 count(case
when tb.Suppliers_Recommended_Date_Fact = '0000-00-00 00:00:00'
then null  
else tb.Suppliers_Recommended_Date_Fact end ) as supReDateFact,
count(case
when tb.evaluation_Methods_Date_Fact = '0000-00-00 00:00:00'
then null  
else tb.evaluation_Methods_Date_Fact end) as evaMethDateFact,
 count(case when tb.bid_Date_Fact = '0000-00-00 00:00:00'then
null  else tb.bid_Date_Fact end) as bidDateFact,
count(case when tb.inquiry_Issued_Date_Fact = '0000-00-00 00:00:00'then
null  else tb.inquiry_Issued_Date_Fact end) as inqIssDateFact,
count(case when tp.purchase_mrzheng_endtime = '0000-00-00 00:00:00'then
null  else tp.purchase_mrzheng_endtime end) as proRecConfirmDateFact,
count(case when tp.contract_mrzheng_endtime = '0000-00-00 00:00:00'then null  
else tp.contract_mrzheng_endtime end) as conAppDateFact
 from tb_pmi_project_management tb
left join
tb_purchase_check tp
on tb.requisition_Num = tp.requisition_Num
left join system_dict d on d.code=tb.procurement_Method
left join
(select case when d.name='邀请招标' then '邀请招标(>=50万)'
when d.name='单一采购' then '单一采购' when d.name='快速采购' then '快速采购(5-50万)' end as proMethod,s.procurement_Method,count(s.isPRproject )as HasNo
from  tb_pmi_project_management s
left join system_dict d on d.code=s.procurement_Method
where s.is_Count =1 and s.isDelete = 0 and s.isPRproject = 0
and year(s.PR_Reception_Time) = YEAR(NOW( )) and s.budgetyear = YEAR(NOW( )) group by s.isPRproject,s.procurement_Method
) a
on
tb.procurement_Method = a.procurement_Method
left join
(select case when d.name='邀请招标' then '邀请招标(>=50万)'
when d.name='单一采购' then '单一采购' when d.name='快速采购' then '快速采购(5-50万)' end as proMethod,s.procurement_Method,sum(s.isPRproject )as HasYes
from  tb_pmi_project_management s
left join system_dict d on d.code=s.procurement_Method
where s.is_Count =1 and s.isDelete = 0 and s.isPRproject = 1
and year(s.PR_Reception_Time) = YEAR(NOW( )) and s.budgetyear = YEAR(NOW( )) group by s.isPRproject,s.procurement_Method
) b
on
tb.procurement_Method = b.procurement_Method
where tb.is_Count =1
and tb.isDelete = 0
and year(tb.PR_Reception_Time) = YEAR(NOW( ))
and tb.budgetyear = YEAR(NOW( ))  
group by
tb.procurement_Method

posted @ 2016-04-14 20:13  SH一03  阅读(133)  评论(0编辑  收藏  举报