次の 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_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 に対して適切に機能するよりも (また、手動でクエリに挿入する場合は任意の値に対しても)。しかし、1 つのクエリを使用してすべてのアイテムを取得したいと考えています。
何が問題なのですか?
アップデート。
shop_items.section_id
次の形式の値が含まれています:parent_section.child_section_1.child_section_2.child_section_3など。アイテムのページのページネーションにこれが必要です。
の値shop_sections.parent_id
は同じ形式です。
私がやりたいのは、セクションのツリーと各セクションのアイテム数を表示することだけです。