select *,'月' as tjlb1,count(distinct substring(dm,1,4)) as 数into #slfrom BK (nolock)where substring(cyrq,1,7)='${tjrq}'+'-'+'${tjsj}'unionselect *,'季' as tjlb1,count(distinct substring(dm,1,4)) as 数from BK (nolock)where case when substring(cyrq,6,2) in ('01','02','03') then substring(cyrq,1,4)+'一季度' when substring(cyrq,6,2) in ('04','05','06') then substring(cyrq,1,4)+'二季度' when substring(cyrq,6,2) in ('07','08','09') then substring(cyrq,1,4)+'三季度' when substring(cyrq,6,2) in ('10','11','12') then substring(cyrq,1,4)+'四季度' end ='${tjrq}'+'${tjsj}'unionselect *,'年' as tjlb1,count(distinct substring(dm,1,4)) as 数from BK (nolock)where substring(cyrq,1,4) ='${tjrq}'group by czrqselect * from #sl (nolock)where tjlb1='${tjlb}'