需求是这样:一个企业可以有多个资质信息,查询用户选择的资质信息的企业。图如下:
sql语句如下,SELECT * from T_Enterprise_BaseInfo where exists
( select distinct EPID from T_EntBI_EntQ e where
exists (select 1 from T_EntBI_EntQ f where QID = 1 and a.EPID = f.EPID )
and exists (select 1 from T_EntBI_EntQ g where QID = 2 and a.EPID = g.EPID )
and exists (select 1 from T_EntBI_EntQ h where QID = 5 and a.EPID = h.EPID )
)
一个 T_EntBI_EntQ 表中一个企业可以有多个资质,如果当前epid可以查到这些资质就说明这个epid满足条件。