创建物化视图的脚本V_APPT_RECORD
CREATE MATERIALIZED VIEW ods_qyhyc.V_APPT_RECORD
DISTRIBUTED BY HASH( APPT_ID,ORG_CODE ) BUCKETS
3 -- 分桶 一般 3- 4 个就行了
REFRESH ASYNC START("2023-10-18 03:02:00") EVERY(interval 5 HOUR) as
SELECT
A.APPT_ID
,T_DIM_ORG.ORG_CODE
,T_DIM_ORG.ORG_NAME
,A.APPT_SRC_ID
,A.ORDER_CODE
,A.SRC_DETL_ID
,A.APPT_CHAN_CODE
,A.USER_ID
,A.APPT_TIME
,A.ORG_ID
,A.DEPT_ID
,A.APPT_STATE
,A.TAKE_STATE
,A.VISIT_STATE
,A.PAYMENT_STATE
,A.RECORD_CLASS
,A.APLY_ID
,A.IS_PATIENT
,A.PATIENT_ID
,A.PATIENT_NAME
,A.PATIENT_IDCARD
,A.PATIENT_TEL
,A.INS_NO
,A.OUT_SNO
,A.VISIT_DATE
,A.PAY_MODE
,A.HIS_MONEY
,A.HANDLE
,A.HANDLE_TIME
,A.CANCEL_DT
,A.CANCEL_REASON_CODE
,A.CANCEL_EXP
,A.REC_CREATE_USER
,A.REC_CREATE_TIME
,A.REC_MODIFY_USER
,A.REC_MODIFY_TIME
,A.SKD_DATE
,A.CHAN_ORDER_CODE
,A.PATIENT_IDCODE
,A.DISEASE_NAME
,A.APPT_COME_FROM
,A.PATIENT_BIRTHDAY
,A.PATIENT_SEX
,A.CHAN_DETL_ID
,A.SORT_NUM
,A.ORDER_NO
,A.REFUND_ORDER_NO
,A.AGT_REFUND_ORDER_NO
,A.IS_COMMUNITY
,A.GUARD_PNAME
,A.GUARD_SEX
,A.GUARD_IDCARD
,A.GUARD_BIRTHDAY
,A.GUARD_MOBILE
,A.GUARD_INSURANCE_CARD
,A.GUARD_MEDICAL_CARD
,A.INSURANCE_SER_NUM
,A.ADD_FLAG
,A.ORDER_TYPE
,A.APPT_COME_UN
,A.PAY_SNO
,A.PAY_DATE
,A.PAY_COME_UN
,A.INSURANCE_CP_NO
,A.INSURANCE_TYPE
,A.BLACK_STATUS
,A.SK_ORG_NAME
,A.SK_DEPT_NAME
,A.SK_EMP_NAME
,A.SK_REFERRNAL_SIGN
,A.ADDR_CODE
,A.ADDR_NAME_ALL
,A.LEVEL_ID
,A.EMP_ID
,A.IN_BEGIN_TIME
,A.IN_END_TIME
,A.LAST_EDITED_TIME
,A.CDC_CREATE_TIME
,A.UD_CREATE_TIME
,A.UD_UPDATE_TIME
FROM ods_qyhyc.APPT_RECORD A
inner join ods_qyhyc.T_ORGANIZATION ON T_ORGANIZATION.ID=A.ORG_ID
inner JOIN dim_odr.T_DIM_ORG ON T_DIM_ORG.ORG_CODE=T_ORGANIZATION.ORG_CODE
union all
SELECT
A.APPT_ID
,T_DIM_ORG.ORG_CODE
,T_DIM_ORG.ORG_NAME
,A.APPT_SRC_ID
,A.ORDER_CODE
,A.SRC_DETL_ID
,A.APPT_CHAN_CODE
,A.USER_ID
,A.APPT_TIME
,A.ORG_ID
,A.DEPT_ID
,A.APPT_STATE
,A.TAKE_STATE
,A.VISIT_STATE
,A.PAYMENT_STATE
,A.RECORD_CLASS
,A.APLY_ID
,A.IS_PATIENT
,A.PATIENT_ID
,A.PATIENT_NAME
,A.PATIENT_IDCARD
,A.PATIENT_TEL
,A.INS_NO
,A.OUT_SNO
,A.VISIT_DATE
,A.PAY_MODE
,A.HIS_MONEY
,A.HANDLE
,A.HANDLE_TIME
,A.CANCEL_DT
,A.CANCEL_REASON_CODE
,A.CANCEL_EXP
,A.REC_CREATE_USER
,A.REC_CREATE_TIME
,A.REC_MODIFY_USER
,A.REC_MODIFY_TIME
,A.SKD_DATE
,A.CHAN_ORDER_CODE
,A.PATIENT_IDCODE
,A.DISEASE_NAME
,A.APPT_COME_FROM
,A.PATIENT_BIRTHDAY
,A.PATIENT_SEX
,A.CHAN_DETL_ID
,A.SORT_NUM
,A.ORDER_NO
,A.REFUND_ORDER_NO
,A.AGT_REFUND_ORDER_NO
,A.IS_COMMUNITY
,A.GUARD_PNAME
,A.GUARD_SEX
,A.GUARD_IDCARD
,A.GUARD_BIRTHDAY
,A.GUARD_MOBILE
,A.GUARD_INSURANCE_CARD
,A.GUARD_MEDICAL_CARD
,A.INSURANCE_SER_NUM
,A.ADD_FLAG
,A.ORDER_TYPE
,A.APPT_COME_UN
,A.PAY_SNO
,A.PAY_DATE
,A.PAY_COME_UN
,A.INSURANCE_CP_NO
,A.INSURANCE_TYPE
,A.BLACK_STATUS
,A.SK_ORG_NAME
,A.SK_DEPT_NAME
,A.SK_EMP_NAME
,A.SK_REFERRNAL_SIGN
,A.ADDR_CODE
,A.ADDR_NAME_ALL
,A.LEVEL_ID
,A.EMP_ID
,A.IN_BEGIN_TIME
,A.IN_END_TIME
,A.LAST_EDITED_TIME
,A.CDC_CREATE_TIME
,A.UD_CREATE_TIME
,A.UD_UPDATE_TIME FROM
ods_qyhyc.APPT_RECORD_HIS A
inner join ods_qyhyc.T_ORGANIZATION ON T_ORGANIZATION.ID=A.ORG_ID
inner JOIN dim_odr.T_DIM_ORG ON T_DIM_ORG.ORG_CODE=T_ORGANIZATION.ORG_CODE
WHERE NOT EXISTS (
SELECT 1 FROM ods_qyhyc.APPT_RECORD A1 WHERE A1.APPT_ID=A.APPT_ID
) AND A.SKD_DATE>='2018-01-01'
创建完成后,提示刷新成功后, 数据量2700W+ 。
------------ 第一种情况, 关联创建物化视图 ------------------------
用V_APPT_RECORD新建其他物化视图
CREATE MATERIALIZED VIEW dwd_odr.MV_DWD_预约_门诊明细
DISTRIBUTED BY HASH(机构代码,预约记录ID ) BUCKETS
3 -- 分桶 一般 3- 4 个就行了
REFRESH ASYNC START("2023-10-18 03:02:00") EVERY(interval 6 HOUR) as
select
A.ORG_CODE AS 机构代码
,A. APPT_ID 预约记录ID
,A.ORG_NAME AS 机构名称
,A. ORDER_CODE 订单编号
,A. CHAN_ORDER_CODE 渠道订单编号
,A. CHAN_DETL_ID 渠道的号源明细id
,A. APPT_SRC_ID 号源标识
,A. ORDER_NO 渠道方产生的订单号
,A. SRC_DETL_ID 号源分时标识
,A. APPT_CHAN_CODE 预约渠道编码
,A. SKD_DATE 排班出诊日期
,A. USER_ID 预约人ID
,A.PATIENT_NAME 就诊人姓名
,A.PATIENT_SEX 性别
,A.PATIENT_BIRTHDAY 出生日期
,A.PATIENT_IDCODE 就诊人证件代码
,A.PATIENT_IDCARD 就诊人证件号码
,A. APPT_TIME 用户操作预约时间
,A. ORG_ID 预约机构ID
,A.APPT_STATE 预约订单状态代码
,case A.APPT_STATE when -3 then'取号后退号'when -2 then'停诊'when -1 then'预约取消'when 1 then'预约成功'when 2 then '已付费' when 3 then '已取号' when 4 then'已挂号'when 5 then'已就诊'when 9 then'爽约' else A.APPT_STATE END 预约订单状态名称
,A. PAYMENT_STATE 支付状态代码
,case A.PAYMENT_STATE when 0 then'未付款'when 1 then'已付款'when 2 then'已退费'else A.PAYMENT_STATE end 支付状态名称
,case when A. ADD_FLAG='1' then 1 else 0 end 加号标识
,A. ORDER_TYPE 订单类型代码
,case when A.ORDER_TYPE is null then'病人在线预约'when A.ORDER_TYPE='2'then'医生诊间预约'when A.ORDER_TYPE='3'THEN'现场预约'ELSE A.ORDER_TYPE END 订单类型名称
,A.DEPT_ID 预约科室ID
,case A.IS_COMMUNITY when '2' then '1' else 0 end 是否为社康预约
,A.ORDER_CODE 区域号源池挂号预约序号
,case when A.APPT_STATE>=0 and A.APPT_STATE<>9 THEN 1 ELSE 0 END 有效预约标志
,T_EMPLOYEE_CONTRAST.EMP_CODE as 预约医生工号
,T_EMPLOYEE_CONTRAST.EMP_NAME as 预约医生姓名
,YYKS.DEPT_CODE 院内_科室_编码
,YYKS.DEPT_NAME 院内_科室_名称
,YYKS.RHIN_CD 区域联网_编码体系
,YYKS.RHIN_CODE 区域联网_编码
,YYKS.RHIN_NAME 区域联网_名称
,YYKS.GHKSDM AS 预约挂号科室代码
,YYKS.GHKSMC AS 预约挂号科室名称
,YYKS.JZKSDM 预约挂号对应的门诊科室代码
,YYKS.JZKSMC 预约挂号对应的门诊科室名称
,ifnull(YYKS.科室代码,'其他') as 科室代码
,ifnull(YYKS.科室名称,'其他') as 科室名称
,MS_GHMX.YYXH AS HIS挂号预约序号
,MS_GHMX.YYKSSJ AS 预约开始时间
,MS_GHMX.YYJSSJ AS 预约结束时间
,MS_GHMX.YYSD AS 预约时段
,MS_GHMX.SBXH AS 挂号序号
,MS_GHMX.BRID as 病人编号
,MS_GHMX.MS_GHMX_KSDM AS 挂号科室代码
,MS_GHMX.MS_GHKS_KSMC AS 挂号科室名称
,MS_GHMX.MZKS AS 挂号对应的门诊科室代码
,MS_GHMX.BRLY 病人来源
,MS_GHMX.互联网医院标志
,MS_GHMX.JZXH AS 就诊序号
,MS_GHMX.KSSJ AS 就诊开始时间
,MS_GHMX.GHSJ AS 挂号时间
,CASE WHEN
(MS_GHMX.YYKSSJ IS NULL OR MS_GHMX.KSSJ IS NULL OR (MS_GHMX.YYKSSJ>=MS_GHMX.KSSJ))THEN 0
ELSE TIMESTAMPDIFF(MINUTE,MS_GHMX.YYKSSJ,MS_GHMX.KSSJ) END AS 预约就诊时差
,MS_GHMX.YSDM AS 就诊医生代码
,MS_GHMX.YS_MZ_JZLS_KSDM AS 就诊科室代码
,MS_GHMX.业务科室名称 就诊科室名称
,MS_GHMX.科室代码_就诊 科室代码_就诊标准
,MS_GHMX.科室名称_就诊 科室名称_就诊标准
from ods_qyhyc.V_APPT_RECORD A
-- INNER JOIN ods_qyhyc.V_APPT_SRC on V_APPT_SRC.APPT_SRC_ID=A.APPT_SRC_ID
-- left JOIN ods_qyhyc.V_APPT_SRC_DETL B on A.SRC_DETL_ID=B.SRC_DETL_ID
-- select * from ods_qyhyc.T_DICT_EMPLOYEE
left join ods_qyhyc.T_EMPLOYEE_CONTRAST ON T_EMPLOYEE_CONTRAST.P_ID=A.EMP_ID AND T_EMPLOYEE_CONTRAST.SYS_ID= 1 AND T_EMPLOYEE_CONTRAST.SYS_VERS='HC01'
LEFT JOIN dwd_odr.MV_DWD_预约_门诊明细_科室关联 YYKS ON YYKS.ID=A.DEPT_ID
LEFT JOIN dwd_odr.MV_DWD_预约_门诊明细_门诊挂号就诊 MS_GHMX ON A.ORDER_CODE=MS_GHMX.YYHM AND A.ORG_CODE=MS_GHMX.ORG_CODE
查询字典表 物化视图 已经success
查询 MV_DWD_预约_门诊明细 的数据量 只有 240条。
物化视图MV_DWD_预约_门诊明细的select 语句 查询总数 应该有 2700W+ 的数据量。
---------第二种 不关联其他 创建物化视图 ---------------
CREATE MATERIALIZED VIEW dwd_odr.MV_DWD_预约_门诊明细
DISTRIBUTED BY HASH(机构代码,预约记录ID ) BUCKETS
3 -- 分桶 一般 3- 4 个就行了
REFRESH ASYNC START("2023-10-18 03:02:00") EVERY(interval 6 HOUR) as
select
A.ORG_CODE AS 机构代码
,A. APPT_ID 预约记录ID
,A.ORG_NAME AS 机构名称
,A. ORDER_CODE 订单编号
,A. CHAN_ORDER_CODE 渠道订单编号
,A. CHAN_DETL_ID 渠道的号源明细id
,A. APPT_SRC_ID 号源标识
,A. ORDER_NO 渠道方产生的订单号
,A. SRC_DETL_ID 号源分时标识
,A. APPT_CHAN_CODE 预约渠道编码
,A. SKD_DATE 排班出诊日期
,A. USER_ID 预约人ID
,A.PATIENT_NAME 就诊人姓名
,A.PATIENT_SEX 性别
,A.PATIENT_BIRTHDAY 出生日期
,A.PATIENT_IDCODE 就诊人证件代码
,A.PATIENT_IDCARD 就诊人证件号码
,A. APPT_TIME 用户操作预约时间
,A. ORG_ID 预约机构ID
,A.APPT_STATE 预约订单状态代码
,case A.APPT_STATE when -3 then'取号后退号'when -2 then'停诊'when -1 then'预约取消'when 1 then'预约成功'when 2 then '已付费' when 3 then '已取号' when 4 then'已挂号'when 5 then'已就诊'when 9 then'爽约' else A.APPT_STATE END 预约订单状态名称
,A. PAYMENT_STATE 支付状态代码
,case A.PAYMENT_STATE when 0 then'未付款'when 1 then'已付款'when 2 then'已退费'else A.PAYMENT_STATE end 支付状态名称
,case when A. ADD_FLAG='1' then 1 else 0 end 加号标识
,A. ORDER_TYPE 订单类型代码
,case when A.ORDER_TYPE is null then'病人在线预约'when A.ORDER_TYPE='2'then'医生诊间预约'when A.ORDER_TYPE='3'THEN'现场预约'ELSE A.ORDER_TYPE END 订单类型名称
,A.DEPT_ID 预约科室ID
,case A.IS_COMMUNITY when '2' then '1' else 0 end 是否为社康预约
,A.ORDER_CODE 区域号源池挂号预约序号
,case when A.APPT_STATE>=0 and A.APPT_STATE<>9 THEN 1 ELSE 0 END 有效预约标志
from ods_qyhyc.V_APPT_RECORD A
此时 还是只有240条数据 。