从表中选择值,ID在一列中

时间:2016-06-08 07:55:10

标签: mysql

我有这个MySQL查询效果很好,我只需要为advantages.value中的每个ID抓取properties.advantages.正如您在图片中看到的那样,列优势很明确(至少对我而言,我没有创建这个),ID由-分隔。我怎样才能获得这些价值观?

SELECT 
properties.id,
(SELECT types.value FROM types WHERE types.id = properties.type_id) as types,
properties.price,
properties.town_id,

**( SELECT advantages......),**

towns.id, 
towns.value 
FROM properties
LEFT JOIN towns
ON properties.town_id=towns.id 
WHERE properties.published='1' 

enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

我猜这是和你一起遇到麻烦的?

**( SELECT advantages......),**

您可以LIKECONCAT()一起使用来比较它们:

SELECT a.advantagesCol FROM advantages a
WHERE CONCAT('-',properties.id,'-') LIKE a.Id_Column