帆软FCP开发认证模拟第二题
原题目
数据库查询结果
with base_data as (
select id,part, substr(part, 1, instr(part || ';', ';') - 1) code,substr(part, instr(part || ';', ';') + 1) as remaining
from chq3g4
where part != '' AND part IS NOT NULL
),
all_data as (
select id,code from base_data
union all
select '12' as id, remaining as code from base_data where remaining!=''
),
area_data as (
select id,substr(code,0,instr(code,':')) as area
from all_data where area!=''
),
area_temp_data as (
select id,substr(code,0,instr(code,':')) as area
from all_data where area=''
),
category_data as (
select id,code,substr(code,instr(code,':')+1,2) as category,substr(code,instr(code,':')+4) as category_after
from all_data where id not in (select id from area_temp_data)
),
num_data as (
select id,category_after,substr(category_after,0,instr(category_after,':')) as num,substr(category_after,instr(category_after,':')+1) num_after
from category_data
),
base_result as (
select t1.id, t3.area,t2.category,if(num='',0,num) as num,if(num_after='','20151220',num_after) as date_strfrom num_data t1
left join category_data t2 on t1.id=t2.id
left join area_data t3 on t1.id=t3.id
),
handler_data as (
select case when area='225100' then '上海'when area='225200' then '江苏'when area='225300' then '浙江'end as city,category,num, date_str,substr(date_str,1,4)||'-'||substr(date_str,5,2)||'-'||substr(date_str,7) as shift_date
from base_result
)
select city,category,num,date_str,shift_date
from handler_data
where 1=1
--AND shift_date >= '${shift_date_start}'
--AND shift_date <= '${shift_date_end}'在这里插入代码片
帆软结果
```xml
select city,category,num,date_str,shift_date,case when category='01' then '分类01'when category='02' then '分类02'when category='03' then '分类03'end as category_
from handler_data
where 1=1
AND shift_date >= '${shift_date_start}'
AND shift_date <= '${shift_date_end}'