SQL代码的编码原则如下:
SQL代码的编码规范如下:
-- MaxCompute(ODPS) SQL
--**************************************************************************
-- ** 所属主题: 交易
-- ** 功能描述: 交易退款分析
-- ** 创建者 : 有码
-- ** 创建日期: 20170616
-- ** 修改日志:
-- ** 修改日期 修改人 修改内容
-- yyyymmdd name comment
-- 20170831 无码 增加对biz_type=1234交易的判断
--**************************************************************************
字段排列要求
对case语句编排作如下约定:
--**************************************************************************
-- step1 清理当天的数据分区
--**************************************************************************
insert overwrite table dw_ckd_ocr_data
select coalesce(a.record_id,b.record_id) as record_id
,coalesce(a.type,b.type) as type
,coalesce(a.name,b.name) as name
,coalesce(a.createtime,b.createtime) as createtime
,coalesce(a.updatetime,b.updatetime) as updatetime
,a.`入院日期`
,a.`出院日期`
,a.`出院记录/出院小结`
,b.`氯吡格雷用药信息`
from (
select record_id
,type
,name
,to_char(updatetime, 'yyyy-mm-dd HH:MM') as updatetime
,to_char(createtime, 'yyyy-mm-dd HH:MM') as createtime
,WM_CONCAT(',',get_json_object(ocr_data,'$.data[0].入院日期')) as `入院日期`
,WM_CONCAT(',',get_json_object(ocr_data,'$.data[0].出院日期')) as `出院日期`
,WM_CONCAT('',get_json_object(ocr_data,'$.data[0].出院记录/出院小结')) as `出院记录/出院小结`
from ods_ocr_imgs
where name = '上传出院小结'
and status=2
and uid in (
select trans_array(0,",",replace(replace(ocr_imgs,'[',''),']','')) as (ocr_imgs)
from ods_ocr_records
where project_id = '580f7eb5-7462-4755-80d9-70d25ac8be23'
and valid = true
and ocr_imgs != "[]"
)
group by record_id
,type,name
,status
,to_char(updatetime, 'yyyy-mm-dd HH:MM')
,to_char(createtime, 'yyyy-mm-dd HH:MM')
) a
full outer join (
select record_id
,type
,name
,to_char(updatetime, 'yyyy-mm-dd HH:MM') as updatetime
,to_char(createtime, 'yyyy-mm-dd HH:MM') as createtime
,get_json_object(ocr_data,'$.data[0].氯吡格雷用药信息') as `氯吡格雷用药信息`
from ods_ocr_imgs
where name = '上传处方'
and status=2
and uid in (
select trans_array(0,",",replace(replace(ocr_imgs,'[',''),']','')) as (ocr_imgs)
from ods_ocr_records
where project_id = '580f7eb5-7462-4755-80d9-70d25ac8be23'
and valid = true
and ocr_imgs != "[]"
)
) b
on a.record_id=b.record_id;
SQL代码编码原则与规范