任务是添加查询功能,要求根据输入的商品名称进行模糊查询
画面表示内容:A表的a1列,a2列,C表的name列。
A表与C表没有直接关联,A表中的a2列与B表b1列关联,B表中的b2列与C表c1列关联,建立模糊查询如下
(B.b0,A.a0,A.a00 三列,是原本SQL中有的条件)
select A.,B.,C.*
from A
left join B on B.b1= A.a1
left join C on C.c1 = B.b2
where (C.name like ‘%’||#medicName#||’%’ or C.default_name like ‘%’||#medicName#||’%’)
order by A.id
以下记录我原本错误的想法,导致我认为不能建立这样的查询:
select name, default_name,id
from YM_C_MEDICINE
where id in (select srm.medic_id
from ym_c_sale_regulation_medic srm
where srm.sts <> ‘0’
and srm.regulation_id in
(select sr.id
from YM_C_SALE_REGULATION sr
where sr.sts <> ‘0’
and sr.parent_org_code = ‘YMO0000365’))
and (name like ‘%%’ or default_name like ‘%%’)