通过or
来查询出符合任意一个条件的数据,group by
主表分组 并且关联表条目数量要等于规格数量即可。
sql
语句 模糊查询地径 like
5.6 及 高度like
3.5 的主表数据:
SELECT
d.SID
FROM
T_FK_SPECIFICATION_PROJECT_DETAIL AS fk
LEFT JOIN T_PROJECT_ENGINEER_DETAIL AS d ON d.SID = fk.PROJECT_DETAIL_SID
LEFT JOIN T_OBJECT_SPECIFICATION AS attr ON attr.`CODE` = fk.ATTR_VALUE_CODE
WHERE
attr.ATTR_VALUE LIKE 'D5.6%'
OR attr.ATTR_VALUE LIKE 'H>3.5%'
GROUP BY
d.SID
HAVING
count(DISTINCT(attr.ATTR_VALUE)) = 2
LIMIT 0,10
结果:
表结构内容如下:
关联表T_FK_SPECIFICATION_PROJECT_DETAIL:
主表T_PROJECT_ENGINEER_DETAIL:
规格键名表T_OBJECT_SPECIFICATION_KEY:
规格键值表T_OBJECT_SPECIFICATION: