SQL查询一个字段与关联表的多个属性值
SELECT
b.establishedTime,b.county,
b.type,
b.companyName,
CONCAT(
substring(b.contacts, 1, 3),
'/',
RIGHT (b.contacts, 11)
) AS contacts,
b.address,
b.imgUrl,
GROUP_CONCAT(a. NAME) AS NAME
FROM
t_info_commercedata_type a
RIGHT JOIN t_info_commercedata b ON FIND_IN_SET(a.id, b.type) > 0
WHERE
1 = 1
<if test="pd.establishedTime!=null and pd.establishedTime!=''"><!-- 成立年份检索 -->
and establishedTime = #{pd.establishedTime}
</if>
<if test="pd.county!=null and pd.county!=''"><!-- 选择地区检索 -->
and county = #{pd.county}
</if>
<if test="pd.id!=null and pd.id!=''"><!-- 选择类别检索 -->
and type = #{pd.id}
</if>
GROUP BY b.type
ORDER BY b.companyName desc