MYSQL连接中的REGEXP工作不正常

MYSQL连接中的REGEXP工作不正常,mysql,regex,join,Mysql,Regex,Join,我还有一个mysql查询: SELECT shop_sections.title, shop_sections.id, shop_sections.parent_id, count(shop_items.id) AS items FROM shop_sections LEFT JOIN shop_items ON shop_items.section_id REGEXP "^" + shop_sectio

我还有一个mysql查询:

SELECT 
    shop_sections.title, 
    shop_sections.id, 
    shop_sections.parent_id, 
    count(shop_items.id) AS items
FROM 
    shop_sections 
LEFT JOIN 
    shop_items 
ON 
    shop_items.section_id 
        REGEXP "^" + shop_sections.parent_id + "([[.full-stop.]].*|$)" 
GROUP BY 
    shop_sections.id
REGEXP执行不正确。对于行
shop\u items.section\u id
=1,它获取所有带有字段
shop\u items.section\u id
且以“1”开头的行(即13.14或13.15,但必须获取1或1.*(1.1、1.2、1.2.3等)

我注意到如果改变

REGEXP“^”+shop_sections.parent_id+”([[.句号].*.|$)”

REGEXP“^1([[.句号]].*.|$)”

然后,它对1正常工作(如果手动将其插入查询,则对任何值也正常工作)。但我想使用一个查询获取所有项

有什么问题吗

UPD.

shop_items.section_id
包含下一个表单中的值:parent_section.child_section_1.child_section_2.child_section_3等。我需要它来分页项目页面

shop\u部分中的值。父id
具有相同的形式


我只想显示一个节树和每个节的若干项。

+
不能用于MySQL中的连接。你的测试应该是:

ON 
  shop_items.section_id 
    REGEXP CONCAT('^', shop_sections.parent_id, '([[.full-stop.]].*|$)')
得到的奇怪结果是由于执行加法的断开连接。假设
shop\u sections.parent\u id
为1,则:

'^' + shop_sections.parent_id + '([[.full-stop.]].*|$)'

。。。真正计算的是
0+1+0
(转换为整数的字符串计算为0,除非它们以数字序列开头),用作正则表达式相当于无用的
'1'

为什么在
部分的
中使用它?你的加入条件是什么?
shop\u部分
shop\u项目
关联条件是
REGEXP
。在前面的查询中,我使用了
LIKE
,但我需要
REGEXP
。哦,天哪,这真是一个糟糕的模式,那么在
条件下
中没有
REGEXP
怎么办呢?不。问题是,您以错误的方式实现了多对多。对于real N:M,您有另一个关系表,并在连接条件中使用
=
,而不使用任何正则表达式或类似规则