多表关联的视图产生重复行的原因 ----笛卡尔积
今天处理两个报障都是关于视图优化的问题
select
left(b.code_record,10)as DJLSH,
(CASEd.yl_code WHEN 'QT' then (d.yl_code+'-'+left(a.ybh,2)) else d.yl_code end ) as XMBH,
d.item_nameas XMMC,
c.test_value2as JG,
c.text_danweias DW,
c.text_rangeas CKFW,
e.nameas SHR,
a.date_reportas SHRQ,
c.text_noteas PROMPT
fromut_check_result c, ut_check_collection b
,ut_check_patienta
,UT_DICT_USERe
,UT_DICT_ITEMSd
where
b.date_Test=c.test_dateand b.ybh=c.ybh
anda.date_Test=c.test_date and a.ybh=c.ybh
anda.Reporter=e.user_id
andb.patient_kind='3'
anda.flag_send='5'
andb.code_record<>''
andb.date_test>'2014-01-01'
andc.item_code=d.item_code
在视图中看到重复行很多
视图语句如下
left(b.code_record,10)
(CASE
d.item_name
c.test_value2
c.text_danwei
c.text_range
e.name
a.date_report
c.text_note
from
,ut_check_patient
,UT_DICT_USER
,UT_DICT_ITEMS
where
b.date_Test=c.test_date
and
and
and
and
and
and
and
因为关联的表较多,如果不对表字段熟悉,没有过多去关注一对多的原因,产生笛卡尔积数据是几何倍数增长的
以后如果遇到此类状况应第一时间想到这个问题
浙公网安备 33010602011771号