这是我数据库的表结构 (postgresql):
你的表结构
在上面这个 csv 中,包含了我数据库里面的所有表格,以及表格之间的关系。
接下来我会用自然语言描述我想对数据库的操作,你帮我转化成 SQL , 并且简明扼要地解释一下这个 SQL
这是我数据库的表结构 (postgresql):
-- Create table
create table REG.REG_RECORD
(
id VARCHAR2(32) not null,
org_name VARCHAR2(50),
org_code VARCHAR2(50) not null,
hosp_name VARCHAR2(50),
hosp_code VARCHAR2(50) not null,
patient_id VARCHAR2(36) not null,
patient_name VARCHAR2(100) not null,
sex VARCHAR2(6) not null,
age VARCHAR2(50),
reg_type VARCHAR2(10) default '0',
reg_sub VARCHAR2(3) default '0',
outpatient_no VARCHAR2(32),
card_no VARCHAR2(30),
card_code VARCHAR2(32),
dept_id VARCHAR2(32) not null,
dept_name VARCHAR2(80),
sitlevel_id VARCHAR2(32) not null,
sitlevel_name VARCHAR2(50),
doctor_id VARCHAR2(32) not null,
doctor_name VARCHAR2(50),
total_money NUMBER(10,2) default 0 not null,
reg_date DATE not null,
reg_time VARCHAR2(20),
queue_no VARCHAR2(10),
is_appoint VARCHAR2(1) default 'N',
regsource INTEGER not null,
backdatetime DATE,
back_clerkname VARCHAR2(50),
back_clerk VARCHAR2(50),
status VARCHAR2(4) default '0' not null,
pay_status VARCHAR2(4) not null,
balanceno VARCHAR2(32),
tollcollector_name VARCHAR2(50),
tollcollector VARCHAR2(32),
pay_time DATE,
create_username VARCHAR2(50),
create_user VARCHAR2(32),
create_date DATE default sysdate,
update_username VARCHAR2(50),
update_user VARCHAR2(52),
update_date DATE,
is_delete VARCHAR2(1) default '0',
updatekey NUMBER generated always as identity (start with 60768),
id_number VARCHAR2(18),
pattypename VARCHAR2(50),
pattypecode VARCHAR2(50),
isrevisit VARCHAR2(1),
insurancetypename VARCHAR2(50),
insurancetypecode VARCHAR2(50),
preferentialschemecode VARCHAR2(50),
assignedunitcode VARCHAR2(50),
assignedunitname VARCHAR2(150),
preferentialschemename VARCHAR2(50),
ordernumber VARCHAR2(50),
attentdoctorcode VARCHAR2(50),
attentdoctorname VARCHAR2(50),
attentdoctortime DATE,
attentdoctordeptcode VARCHAR2(50),
attentdoctordeptname VARCHAR2(50),
bill_no VARCHAR2(50),
start_time VARCHAR2(10),
end_time VARCHAR2(10),
sourse_id VARCHAR2(32),
validtime VARCHAR2(32),
attentdoctordate DATE,
backdatedate VARCHAR2(20),
birthdate DATE,
acid_pat_type CHAR(60),
bmove NUMBER default 0,
movetime DATE,
movetable VARCHAR2(50),
third_orderid VARCHAR2(100),
micp_lock_fee VARCHAR2(50),
micp_agreement_no VARCHAR2(50),
micp_lock_no VARCHAR2(50),
pay_status_bit VARCHAR2(4),
approve_user VARCHAR2(32),
approve_username VARCHAR2(50),
approve_date DATE,
cancel_approve_user VARCHAR2(32),
cancel_approve_username VARCHAR2(50),
cancel_approve_date DATE,
back_reason VARCHAR2(200),
init_out_times INTEGER default 0,
out_times INTEGER default 0,
pay_type VARCHAR2(20),
pay_type_name VARCHAR2(35),
reg_date_time DATE,
reg_type_name VARCHAR2(50),
reg_sub_name VARCHAR2(50),
regsource_name VARCHAR2(50),
status_name VARCHAR2(50),
pay_status_name VARCHAR2(50),
backnum_date DATE,
first_doc_id VARCHAR2(50),
first_doc_name VARCHAR2(50),
first_dept_id VARCHAR2(50),
first_dept_name VARCHAR2(50),
first_visit_date DATE,
time_quantum VARCHAR2(50),
time_quantum_name VARCHAR2(50),
relation_name VARCHAR2(90),
relation_telephone VARCHAR2(50),
relation_type VARCHAR2(50),
dept_address VARCHAR2(50),
trade_flow VARCHAR2(50),
referee_id VARCHAR2(32),
referee_name VARCHAR2(64),
referee_unit VARCHAR2(100),
agio_bdate DATE,
agio_edate DATE,
queue_no_bak VARCHAR2(10)
)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
-- Add comments to the table
comment on table REG.REG_RECORD
is '挂号表';
-- Add comments to the columns
comment on column REG.REG_RECORD.id
is '主键ID';
comment on column REG.REG_RECORD.org_name
is '机构名称';
comment on column REG.REG_RECORD.org_code
is '机构代码';
comment on column REG.REG_RECORD.hosp_name
is '院区名称';
comment on column REG.REG_RECORD.hosp_code
is '院区编码';
comment on column REG.REG_RECORD.patient_id
is '患者id';
comment on column REG.REG_RECORD.patient_name
is '患者姓名';
comment on column REG.REG_RECORD.sex
is '性别:0.未知,1.男,2.女,9.未说明';
comment on column REG.REG_RECORD.age
is '年龄';
comment on column REG.REG_RECORD.reg_type
is '登记类型:1门诊 2急诊';
comment on column REG.REG_RECORD.reg_sub
is '业务子类:0正常、 1表示无号';
comment on column REG.REG_RECORD.outpatient_no
is '门诊号';
comment on column REG.REG_RECORD.card_no
is '卡号';
comment on column REG.REG_RECORD.card_code
is '卡类型编码';
comment on column REG.REG_RECORD.dept_id
is '挂号科室id';
comment on column REG.REG_RECORD.dept_name
is '挂号科室名称';
comment on column REG.REG_RECORD.sitlevel_id
is '坐诊级别id';
comment on column REG.REG_RECORD.sitlevel_name
is '坐诊级别名称';
comment on column REG.REG_RECORD.doctor_id
is '挂号医生id';
comment on column REG.REG_RECORD.doctor_name
is '挂号医生姓名';
comment on column REG.REG_RECORD.total_money
is '挂号总金额';
comment on column REG.REG_RECORD.reg_date
is '挂号日期';
comment on column REG.REG_RECORD.reg_time
is '挂号时间点';
comment on column REG.REG_RECORD.queue_no
is '排队号';
comment on column REG.REG_RECORD.is_appoint
is '是否预约号:N否、Y是';
comment on column REG.REG_RECORD.regsource
is '来源:0未知 、1窗口、2自助设备、3移动终端、4医生站';
comment on column REG.REG_RECORD.backdatetime
is '退号时间';
comment on column REG.REG_RECORD.back_clerkname
is '退号人姓名';
comment on column REG.REG_RECORD.back_clerk
is '退号人id';
comment on column REG.REG_RECORD.status
is '记录状态:0正常、1取消';
comment on column REG.REG_RECORD.pay_status
is '付款状态:0未付、1已付、2已退';
comment on column REG.REG_RECORD.balanceno
is '结算流水号';
comment on column REG.REG_RECORD.tollcollector_name
is '收费员姓名';
comment on column REG.REG_RECORD.tollcollector
is '收费员id';
comment on column REG.REG_RECORD.pay_time
is '付款时间';
comment on column REG.REG_RECORD.create_username
is '创建人姓名';
comment on column REG.REG_RECORD.create_user
is '创建人';
comment on column REG.REG_RECORD.create_date
is '创建时间';
comment on column REG.REG_RECORD.update_username
is '更新人姓名';
comment on column REG.REG_RECORD.update_user
is '修改人';
comment on column REG.REG_RECORD.update_date
is '修改时间';
comment on column REG.REG_RECORD.is_delete
is '删除标志';
comment on column REG.REG_RECORD.updatekey
is '自增长';
comment on column REG.REG_RECORD.id_number
is '身份证号码';
comment on column REG.REG_RECORD.pattypename
is '病人类型名称';
comment on column REG.REG_RECORD.pattypecode
is '病人类型编码';
comment on column REG.REG_RECORD.isrevisit
is '是否复诊病人';
comment on column REG.REG_RECORD.insurancetypename
is '医保类型名称';
comment on column REG.REG_RECORD.insurancetypecode
is '医保类型编码';
comment on column REG.REG_RECORD.preferentialschemecode
is '优惠方案编码';
comment on column REG.REG_RECORD.assignedunitcode
is '合同单位编码';
comment on column REG.REG_RECORD.assignedunitname
is '合同单位名称';
comment on column REG.REG_RECORD.preferentialschemename
is '优惠方案名称';
comment on column REG.REG_RECORD.ordernumber
is '订单号';
comment on column REG.REG_RECORD.attentdoctorcode
is '接诊医生编码';
comment on column REG.REG_RECORD.attentdoctorname
is '接诊医生姓名';
comment on column REG.REG_RECORD.attentdoctortime
is '接诊时间';
comment on column REG.REG_RECORD.attentdoctordeptcode
is '接诊科室编码';
comment on column REG.REG_RECORD.attentdoctordeptname
is '接诊科室名称';
comment on column REG.REG_RECORD.bill_no
is '票据号';
comment on column REG.REG_RECORD.start_time
is '号序开始时间段(08:00:00)';
comment on column REG.REG_RECORD.end_time
is '号序开始时间段(08:06:00)';
comment on column REG.REG_RECORD.sourse_id
is '号源ID';
comment on column REG.REG_RECORD.validtime
is '挂号有效期';
comment on column REG.REG_RECORD.attentdoctordate
is '接诊日期';
comment on column REG.REG_RECORD.backdatedate
is '退号日期';
comment on column REG.REG_RECORD.birthdate
is '出生日期';
comment on column REG.REG_RECORD.acid_pat_type
is '核酸检测人员类型';
comment on column REG.REG_RECORD.bmove
is '迁移状态 0未迁移 1已迁移';
comment on column REG.REG_RECORD.movetime
is '迁移时间 ';
comment on column REG.REG_RECORD.movetable
is '迁移地址';
comment on column REG.REG_RECORD.third_orderid
is '第三方交易号';
comment on column REG.REG_RECORD.micp_lock_fee
is '医后付锁定金额,单位:分';
comment on column REG.REG_RECORD.micp_agreement_no
is '医保信用支付协议号';
comment on column REG.REG_RECORD.micp_lock_no
is '医后付锁定银行流水号';
comment on column REG.REG_RECORD.pay_status_bit
is '支付状态,0=未支付,1=支付';
comment on column REG.REG_RECORD.approve_user
is '审核人';
comment on column REG.REG_RECORD.approve_username
is '审核人姓名';
comment on column REG.REG_RECORD.approve_date
is '审核时间';
comment on column REG.REG_RECORD.cancel_approve_user
is '取消审核人';
comment on column REG.REG_RECORD.cancel_approve_username
is '取消审核人姓名';
comment on column REG.REG_RECORD.cancel_approve_date
is '取消审核时间';
comment on column REG.REG_RECORD.back_reason
is '退签原因';
comment on column REG.REG_RECORD.init_out_times
is '门诊初始就诊次数 ';
comment on column REG.REG_RECORD.out_times
is '门诊就诊次数 ';
comment on column REG.REG_RECORD.pay_type
is '支付方式编码';
comment on column REG.REG_RECORD.pay_type_name
is '������������';
comment on column REG.REG_RECORD.reg_date_time
is '挂号时间=挂号日期+挂号时间点';
comment on column REG.REG_RECORD.reg_type_name
is '������������';
comment on column REG.REG_RECORD.reg_sub_name
is '������������';
comment on column REG.REG_RECORD.regsource_name
is '��������';
comment on column REG.REG_RECORD.status_name
is '������������';
comment on column REG.REG_RECORD.pay_status_name
is '������������';
comment on column REG.REG_RECORD.backnum_date
is '退号日期(时间类型)';
comment on column REG.REG_RECORD.first_doc_id
is '首诊医生ID';
comment on column REG.REG_RECORD.first_doc_name
is '������������';
comment on column REG.REG_RECORD.first_dept_id
is '首诊科室ID';
comment on column REG.REG_RECORD.first_dept_name
is '������������';
comment on column REG.REG_RECORD.first_visit_date
is '��������';
comment on column REG.REG_RECORD.time_quantum
is '班次ID';
comment on column REG.REG_RECORD.time_quantum_name
is '��������';
comment on column REG.REG_RECORD.relation_name
is '联系人';
comment on column REG.REG_RECORD.relation_telephone
is '联系人电话';
comment on column REG.REG_RECORD.relation_type
is '联系人类型,参考国标表';
comment on column REG.REG_RECORD.dept_address
is '科室地址';
comment on column REG.REG_RECORD.trade_flow
is '订单号';
comment on column REG.REG_RECORD.referee_id
is '推荐人ID';
comment on column REG.REG_RECORD.referee_name
is '推荐人姓名';
comment on column REG.REG_RECORD.referee_unit
is '推荐单位';
comment on column REG.REG_RECORD.agio_bdate
is '优惠开始日期';
comment on column REG.REG_RECORD.agio_edate
is '优惠结束日期';
comment on column REG.REG_RECORD.queue_no_bak
is '用于备份QUEUE_NO字段的值';
-- Create/Recreate indexes
create index REG.IDX_REG_RECORD_ATTENTDOCTORTIME on REG.REG_RECORD (ATTENTDOCTORTIME)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_CARD_NO on REG.REG_RECORD (CARD_NO)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_CREATE_DATE on REG.REG_RECORD (CREATE_DATE)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_DEPT_ID on REG.REG_RECORD (DEPT_ID)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_DOCTOR_ID on REG.REG_RECORD (DOCTOR_ID)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create unique index REG.IDX_REG_RECORD_ID on REG.REG_RECORD (ID)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create unique index REG.IDX_REG_RECORD_OUTPATIENT_NO on REG.REG_RECORD (OUTPATIENT_NO)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_PATIENT_ID on REG.REG_RECORD (PATIENT_ID)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_REG_DATE on REG.REG_RECORD (REG_DATE)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_STATUSCOMBO on REG.REG_RECORD (STATUS, IS_DELETE, PATIENT_ID, OUTPATIENT_NO)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_UPDATE_DATE on REG.REG_RECORD (UPDATE_DATE)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
create index REG.IDX_REG_RECORD_VALIDTIME on REG.REG_RECORD (VALIDTIME)
tablespace TS_HIS50_REG_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 1M
next 1M
minextents 1
maxextents unlimited
pctincrease 0
);
在上面这个 csv 中,包含了我数据库里面的所有表格,以及表格之间的关系。
接下来我会用自然语言描述我想对数据库的操作,你帮我转化成 SQL , 并且简明扼要地解释一下这个 SQL
An error occurred with your deployment
EDGE_FUNCTION_INVOCATION_TIMEOUT