最佳答案
我试图找到一种方法,通过函数分组来返回结果。
GROUPBY 正在按预期工作,但我的问题是: 是否可以通过忽略 NULL 字段来拥有一个组。因为我仍然需要指定字段为 NULL 的所有行,所以它不会将 NULL 分组在一起。
SELECT `table1`.*,
GROUP_CONCAT(id SEPARATOR ',') AS `children_ids`
FROM `table1`
WHERE (enabled = 1)
GROUP BY `ancestor`
现在假设我有5行,祖先字段是 NULL,它返回我1行... ... 但是我想要全部5行。