drop table dkhokrzhenghe
select
isnull(kacn.日期2,klt.日期2) as 日期2,
isnull(kacn.日,klt.日) as 日,
isnull(kacn.年月,klt.年月) as 年月,
kacn.kacn当月售出累计4000以上会员人数,kacn.kacn累计会员人数,
klt.klt当月售出累计3000以上会员人数,klt.klt累计会员人数,
gy.gy当月售出累计3000以上会员人数,gy.gy累计会员人数
into dkhokrzhenghe
from
(select * from dkhokr_kacn) as kacn
full join
(select * from dkhokr_klt) as klt
on
kacn.日期2=klt.日期2
full join
(select * from dkhokr_gy) as gy
on
kacn.日期2=gy.日期2
order by kacn.日期2
drop table dkhokrzhenghe1
select *,
isnull(kacn当月售出累计4000以上会员人数,0)+
isnull(klt当月售出累计3000以上会员人数,0)+
isnull(gy当月售出累计3000以上会员人数,0) as 三站符合标准当日新增人数,
isnull((select max(kacn累计会员人数) from dkhokr_kacn where dkhokr_kacn.日期2<=dkhokrzhenghe.日期2 and dkhokr_kacn.年月=dkhokrzhenghe.年月),0)+
isnull((select max(klt累计会员人数) from dkhokr_klt where dkhokr_klt.日期2<=dkhokrzhenghe.日期2 and dkhokr_klt.年月=dkhokrzhenghe.年月),0)+
isnull((select max(gy累计会员人数) from dkhokr_gy where dkhokr_gy.日期2<=dkhokrzhenghe.日期2 and dkhokr_gy.年月=dkhokrzhenghe.年月),0) as 三站符合标准累计人数
into dkhokrzhenghe1
from dkhokrzhenghe
order by 日期2