You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.7 KiB
37 lines
1.7 KiB
2 years ago
|
is_common_adj = loadTable("dfs://pit_stock_ts", "is_common_adj")
|
||
|
is_common_ori = loadTable("dfs://pit_stock_ts", "is_common_ori")
|
||
|
|
||
|
// schema(is_common_ori)
|
||
|
|
||
|
/**
|
||
|
* 单季处理
|
||
|
*/
|
||
|
|
||
|
// 每年第一个季度
|
||
|
tbl_quarter1 = select code, report_period, year(report_period) as year, quarterOfYear(report_period) as current_quarter_accum, appear_at_date from is_common_ori where partition(code, 0), quarterOfYear(report_period) == 1
|
||
|
|
||
|
// 当季累计数据,作为下一季基准
|
||
|
tbl_quarter_accum_base = select code, report_period, year(report_period) as year, quarterOfYear(report_period) + 1 as base_for_quarter_accum, appear_at_date from is_common_ori where partition(code, 0), quarterOfYear(report_period) < 4
|
||
|
|
||
|
// 从第二季开始,去匹配前一季累计基数
|
||
|
tbl_quarter_accum = select code, report_period, year(report_period) as year, quarterOfYear(report_period) as current_quarter_accum, appear_at_date from is_common_ori where partition(code, 0), quarterOfYear(report_period) > 1
|
||
|
|
||
|
tbl_quarter_flux = select tbl_quarter_accum.* from ej(tbl_quarter_accum_base, tbl_quarter_accum, `code`year`base_for_quarter_accum, `code`year`current_quarter_accum)
|
||
|
tbl_quarter_flux = unionAll(tbl_quarter1, tbl_quarter_flux).sortBy!(`code`report_period)
|
||
|
|
||
|
tbl_quarter_flux
|
||
|
|
||
|
/**
|
||
|
* 同比计算
|
||
|
*/
|
||
|
/*
|
||
|
sql1 = select code, report_period, year(report_period) - 1 as last_year, quarterOfYear(report_period) as quarter_of_year from bs_common_ori where code='000001.SZ'
|
||
|
//sql1
|
||
|
|
||
|
sql2 = select code, report_period, year(report_period) as this_year, quarterOfYear(report_period) as quarter_of_year from bs_common_ori where code='000001.SZ'
|
||
|
|
||
|
sql = select sql1.*, sql2.* from ej(sql1, sql2, `code`last_year`quarter_of_year, `code`this_year`quarter_of_year)
|
||
|
|
||
|
sql
|
||
|
*/
|