我有一个下一个 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 执行不正确。对于 row shop_items.section_id
= 1,它获取所有字段shop_items.section_id
以“1”开头的行(即 13.14 或 13.15,但它必须获取 1 或 1.*(1.1、1.2、1.2.3 等))。
我注意到如果改变
REGEXP "^" + shop_sections.parent_id + "([[.full-stop.]].*|$)"
到
REGEXP "^1([[.full-stop.]].*|$)"
比它适用于 1 (如果手动将其插入查询也适用于任何值)。但我想使用一个查询来获取所有项目。
可能是什么问题?
UPD。
shop_items.section_id
包含下一种形式的值:parent_section.child_section_1.child_section_2.child_section_3 等。我需要在项目页面上进行分页。
中的值shop_sections.parent_id
具有相同的形式。
我想要做的就是显示一个部分的树和每个部分的一些项目。