yzm313451(提问者)with temp as (
select
case when update_time >= date_format(update_time,\'%Y-%m-%d 08:00:00\') and update_time < date_format(update_time,\'%Y-%m-%d\') + interval \'1440\' minute then date_format(update_time,\'%Y-%m-%d\')
else (date_format(update_time,\'%Y-%m-%d\')- interval \'1\' day) end as report_date,
efficiency,
num
from `cell-mes`.`pack_package`
where 1=1
and efficiency <>\'/\'
)
select * from (
${if(zq=\'周度\',\"select
concat(\'W\',week(report_date,1)) as index_x,
concat(efficiency,\'%\') as efficiency,
sum(num)/10000 as num ,
sum(num)/sum(sum(num)) over() as proportion
from temp
where yearweek(report_date,1) >= yearweek(\'${select_date}\',1)-4
and yearweek(report_date,1) <= yearweek(\'${select_date}\',1) and report_date = substring_index(\'${select_date}\' - interval \'4\' month,\'-\',2)
group by concat(substring_index(report_date,\'-\',2),\'月\'),efficiency\")}
)m
order by case when m.index_x like \'%月%\' then 1
when m.index_x like \'%W%\' then 2
else 3 end asc
,case when index_x like \'W%\' then replace(index_x,\'W\',\'\')+0 else null end asc
,m.index_x asc