mysql能否实现这样的排序要求?

设有字段a,b.让sql语句以字段a排序,但如果某一条数据的字段a的值为空,则将这条数据排到字段b的值相同的数据下面。

select (case
when C.c = 1 then
null
when C.c = 0 then
C.a
end) a,
C.b
from (select A.*, 0 c
from A
where A.a is not null
union all
select (select min(a2.a) from A a2 where a2.b = a1.b) a, a1.b, 1 c
from A a1
where a1.a is null) C
order by C.a, C.b, C.c;

可能会有些许的问题,因为b字段可能会有重复值,我取得的是a字段的最小值

方案就是,首先将空值的位置填上合适的值,然后排序,再恢复空值就行了