GROUP BY - do not group NULL

后端 未结 6 1023
名媛妹妹
名媛妹妹 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条回答
  •  萌比男神i
    2020-12-05 04:31

    Perhaps you should add something to the null columns to make them unique and group on that? I was looking for some sort of sequence to use instead of UUID() but this might work just as well.

    SELECT `table1`.*, 
        IFNULL(ancestor,UUID()) as unq_ancestor
        GROUP_CONCAT(id SEPARATOR ',') AS `children_ids`
    FROM `table1` 
    WHERE (enabled = 1) 
    GROUP BY unq_ancestor
    

提交回复
热议问题