需求是这样:一个企业可以有多个资质信息,查询用户选择的资质信息的企业。图如下:

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满足条件。
本文介绍了一个复杂的SQL查询案例,该查询用于找出同时拥有特定资质信息的企业。通过使用多个嵌套的EXISTS子句来确保所选企业具备所需的所有资质。

被折叠的 条评论
为什么被折叠?



