MySQL的数字被分割

问题描述 投票:-1回答:1

我在尝试从数据库中获取数据时遇到问题。我想要的数据基于以下列:APractice_theme很难看,并以51|62之类的不好方式列出ID。

根据我的要求:

SELECT art.id,
        art.dateinsertion AS `Date`, 
        IF(art.actif = 1, "publish","future") as Status, 
        art.titre as Title, 
        art.chapeau as Excerpt, 
        art.texte as Content, 
        art.filinkimage as Mage, 
        art.rubrique as Category, 
        GROUP_CONCAT(atheme.titre_theme) as Tag
FROM AParticles as art
    LEFT JOIN AParticles_themes as atheme
        ON art.theme LIKE CONCAT('%',atheme.id,'%')
WHERE just4u_rubrique != ""
GROUP BY art.id  
ORDER BY `art`.`id`  DESC

art.theme返回ID 51|61的列表,我只需要使用LIKE来仅保留整数而不是像5,1这样的分割数

抱歉,如果我不清楚,很难解释这一点。

mysql sql
1个回答
1
投票

要确保只匹配列表中的完整数字,请执行

CONCAT('|',art.theme,'|') LIKE CONCAT('%|',atheme.id,'|%')

另一种方法是:

find_in_set(atheme.id, replace(art.theme,'|',','))
© www.soinside.com 2019 - 2024. All rights reserved.