self.spark.sql('''
create or replace temporary view temp_all_month as
select distinct expns_month_num
from temp_rdt_fin_Dashboard_ctr_anlys a
where year(to_date(substring(a.expns_month_num,1,6),'yyyyMM')) >= year(add_months(date_add(current_date(),-25),-12))
and expns_month_num not like '%13'
''')
#month_list = ['201902','201903' ,'201904','201905','201906','201907','201908','201909','201910','201911','201912'\
# ,'202001','202002','202003' ,'202004','202005','202006','202007','202008','202009','202010','202011','202012']
#
month_df =self.spark.sql('''
select cast(substring(expns_month_num,1,6) as int) as expns_month_num
from temp_all_month a
order by expns_month_num asc ''')
#数据框转化为列表行
rows=month_df.select('expns_month_num').collect()
#转化为列表
month_list = [row.expns_month_num for row in rows]
#先初始化第一个月份
df1=self.spark.sql('''select * from temp_rdt_fin_Dashboard_ctr_anlys_basic ''')
df1.printSchema()
df0 = df1.withColumn('expns_month_num', lit(month_list[0]))
#从列表中扣除第一个
month_list = month_list[1:]
for item in month_list:
df2 = df1.withColumn('expns_month_num', lit(item))
df0 = df0.union(df2)
dt = df0.createOrReplaceTempView('temp_rdt_fin_Dashboard_ctr_anlys_month')