SQL零分割

时间:2011-08-09 20:23:37

标签: sql

如何重写此SQL查询以避免ORDER BY中的除零错误?

SELECT * FROM table WHERE age>'30' ORDER BY (a/b) DESC

1 个答案:

答案 0 :(得分:9)

ORDER BY CASE WHEN b != 0 THEN a / b ELSE 0 END DESC