-- 以下是我 “近五周”参数的数据集 第12行好像就是group by
-- 用于销售预测分析
select a.* from (
select
concat(fiscal_year_name , querate ,
case when length(week_code) =4 then week_code else concat(substr(week_code,1,2),'0',substr(week_code,3,1) ) end )yqws,
min(str_to_date(day_code,'%Y-%m-%d')) week_start_date
from dim_apple_fiscal_year
where
1=1
and day_id <= date_format(date_add(curdate(),INTERVAL + (6-(date_format(curdate(),'%w'))) day) ,'%Y%m%d')
group by fiscal_year_name,querate, week_code
) a where
a.week_start_date >=
(
select date_add(week_start_date,interval -28 day ) from (
select
concat(fiscal_year_name , querate ,
case when length(week_code) =4 then week_code else concat(substr(week_code,1,2),'0',substr(week_code,3,1) ) end )yqws,
min(str_to_date(day_code,'%Y-%m-%d')) week_start_date
from dim_apple_fiscal_year
where
1=1
and day_id <= date_format(date_add(curdate(),INTERVAL + (6-(date_format(curdate(),'%w'))) day) ,'%Y%m%d')
group by fiscal_year_name,querate, week_code
) t
where 1=1
<年季周> and yqws = ifnull(?{年季周},'FY23Q1wk01') </年季周>
limit 1
)
and a.week_start_date <=
(
select week_start_date from (
select
concat(fiscal_year_name , querate ,
case when length(week_code) =4 then week_code else concat(substr(week_code,1,2),'0',substr(week_code,3,1) ) end )yqws,
min(str_to_date(day_code,'%Y-%m-%d')) week_start_date
from dim_apple_fiscal_year
where
1=1
and day_id <= date_format(date_add(curdate(),INTERVAL + (6-(date_format(curdate(),'%w'))) day) ,'%Y%m%d')
group by fiscal_year_name,querate, week_code
) t
where 1=1
<年季周> and yqws = ifnull(?{年季周},'FY23Q1wk01') </年季周>
limit 1
)
|