GROUP BY - do not group NULL

后端 未结 6 1025
名媛妹妹
名媛妹妹 2020-12-05 03:48

I\'m trying to figure out a way to return results by using the group by function.

GROUP BY is working as expected, but my question is: Is it possible to have group b

6条回答
  •  一向
    一向 (楼主)
    2020-12-05 04:36

    SELECT table1.*, 
        GROUP_CONCAT(id SEPARATOR ',') AS children_ids
    FROM table1
    WHERE (enabled = 1) 
    GROUP BY ancestor
           , CASE WHEN ancestor IS NULL
                      THEN table1.id
                      ELSE 0
             END
    

提交回复
热议问题