SQL零分割

Ada*_*ick 1 sql

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

SELECT * FROM table WHERE age>'30' ORDER BY (a/b) DESC
Run Code Online (Sandbox Code Playgroud)

Dan*_*man 9

ORDER BY CASE WHEN b != 0 THEN a / b ELSE 0 END DESC
Run Code Online (Sandbox Code Playgroud)

  • 也许`b <> 0`,如果b是有符号值. (5认同)