Group By Except For Certain Value

后端 未结 4 838
清歌不尽
清歌不尽 2021-01-17 16:18

I\'m trying to create a (sqlite) query that will perform a GROUP BY but will not group anything with the value \'unknown\'. For example, I have the table:

i         


        
4条回答
  •  生来不讨喜
    2021-01-17 16:52

    SELECT 
      MIN(id) AS id,
      IF(tmpname=id,"unknown",tmpname) AS name,
      parent_id,
      school_id
    FROM (
      SELECT 
        id,parent_id,school_id
        IF(name="unknown",id,name) AS tmpname
      FROM 
    ) AS baseview
    GROUP BY tmpname
    

提交回复
热议问题