这是我的表格数据。如果 cat_parent_id 为 0,则表示它是父级,例如 People and Culture 是 cat_id = 1 的父级,Employee Benefits and Certification 是 People and Culture 的子级。但是,员工福利和认证也有孩子。Employee Benefits cat_id = 6,所以他的孩子是SSS Loan Inquiry,而Certification 有一个cat_id = 10,就业证明和SSS 供款证明将是他的孩子。
预期输出:
Admin and Facilities
• Safety and Security Related Concerns
• CCTV Footage
Information Technology
• User Account
• Enable / Disable Access
People and Culture
• Certification
• Certificate of Employment
• SSS Certificate of Employment
• Employee Benefits Request
• SSS Loan Inquiry
我现在有这样的事情没有运气。
SELECT category.cat_id AS catId, category.cat_parent_id AS catParentId,
subcategory.cat_id AS subcatId,subcategory.cat_parent_id AS subcatParentId,
category.cat_name,
CONCAT( IFNULL(subcategory.cat_parent_id, category.cat_parent_id),
category.cat_parent_id, category.cat_id, category.cat_name) AS sorter
FROM ticket_categories AS category
LEFT JOIN ticket_categories AS subcategory ON subcategory.cat_parent_id =
category.cat_id
GROUP BY category.cat_id
ORDER BY sorter
主要目标是按父级(第一优先级)、类别(第二优先级)、子类别(第三优先级)的字母顺序对数据进行排序。我正在使用我的别名分类器,但我无法让它工作。