假如有一张表publishinfo,字段为id,name,type(信息类型),imagepath(图片)  注:type分为3类,字段的值为1,2,3现查询的条件如下:按照type排序,但类型2里边又分为有图的和无图的2种,并且有图的显示在前面,无图的显示在后面各位大虾,这个排序咋弄啊,想了半天也想出来,还请各位大虾多多指教...

解决方案 »

  1.   

    order by type,imagepath不行么?
      

  2.   

    order by case when type=2 and imagepath is null then 2.5 else type end
      

  3.   

    select * 
    from publishinfo
    order by type,case when imagepath is null then 0 else 1 end
      

  4.   

    order by type, decode(length(photo),0,null)如果PHOTO为空或0,都会排到后面。
      

  5.   

    order by case when type=2 and imagepath is null then 2.5 else type end
      

  6.   

    order by type,imagepath nulls last