MYSQL选择与自身和顺序的关系

时间:2016-08-03 13:06:36

标签: mysql mysqli

我有下表

class ChildB : BaseChild<ChildB> { }

// Ok here
var instance = new ChildB(); 

如何选择列问题,以便将其排序为:

id | parent | question
---------------------------------
1  | 0      | Question 1
2  | 0      | Question 2
3  | 2      | SubQuestion 2
4  | 0      | Question 3
5  | 2      | SubQuestion 2

有没有办法?

1 个答案:

答案 0 :(得分:3)

Order by case when parent = 0 then id else parent end, id

fiddle