这里有张桌子
Tag (id, parent_id, title, status)
所有第一级标签NULL都有parent_id. 对于children,属性parent_id中指定id了当前表的parent (一切都很明显)
status- 数字 ( smallint)
您需要进行 SQL 查询以获取所有标签以及不同状态的“孩子”的数量。也就是说,输出将是这样的:
[
'id' => 1,
'title' => 'tag1',
'count_of_status_1' => 2,
'count_of_status_2' => 4
],
[
'id' => 9,
'title' => 'tag2',
'count_of_status_1' => 5,
'count_of_status_2' => 0
],
...
一切都必须写成 clean sql。
你能告诉我这是怎么做到的吗?有可能吗?我对sql表面上熟悉。只在水平上Select ... from ... where。
这是标准的 SQL 关闭:
(演示)