开发者

SQL ORDER BY query

I want to have my table,rcarddet, ordered by "SDNO" (not primary key) in ascending order with the exception of "0". So it should turn out to be like:

1
1 
2
.
.
10
0
0

My query now is:

SELECT * 
  FROM `rca开发者_JS百科rddet` 
 WHERE `RDATE` = '2011-05-25' 
   AND `RCNO` = '1' 
   AND `PLACE` = 'H' 
   AND `SDNO` != 0 
ORDER BY `rcarddet`.`SDNO` ASC;


The easiest way

  SELECT * FROM rcarddet   
   WHERE RDATE = '2011-05-25' and RCNO = '1'and PLACE = 'H'  
ORDER BY CASE  
           WHEN rcarddet.SDNO  = 0 THEN [max_number_for_the_type_of_SDNO]  
           ELSE rcarddet.SDNO   
         END ASC  


SELECT * 
  FROM `rcarddet` 
 WHERE `RDATE` = '2011-05-25' 
   AND `RCNO` = '1' 
   AND `PLACE` = 'H' 
ORDER BY
  `SDNO` = 0,
  `SDNO`;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜