我试图运行以下查询,结果我postgres错误:除零
select request_count,response_count,(response_count*100) / (request_count+response_count) AS proportion from total_dummy_table;
尝试使用以下查询修复,但获得与上面相同的结果
SELECT request_count,(response_count*100) / (request_count) AS proportion FROM total_dummy_table ORDER BY (response_count*100) /(CASE request_count WHEN 0 Then NULL ELSE request_count END) DESC NULLS FIRST
请告诉我我在哪里做错了,或者我该如何解决这个问题.
谢谢!
结果期望:
Request_count | Response_count | Proportion 1603423 | 585706 | 36.52
select request_count,case when request_count+response_count = 0 then 0 else (response_count*100) / (request_count+response_count) end AS proportion from total_dummy_table;