2
#SuperSet 解决除数为0报错 Error: division by zero
source link: https://xmanyou.com/superset-resolve-error-division-by-zero/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
9 June 2023 / SuperSet
#SuperSet 解决除数为0报错 Error: division by zero
用SuperSet进行数据分析时,有时候需要将2列的值相除,此时,如果除数为0,则会报错:
Error: division by zero
比如想用earnings和page_views计算网页价值:
page_rpm = earnings / page_views
如果page_views为0,就会报上边提到的错误。
这可怎么办呢?
这其实不是superset的问题,而是SQL语句的问题。
针对这种情况,可以使用NULLIF
这个SQL函数。
NULLIF 用法
NULLIF需要传入两个参数,然后比较这两个参数的值,如果相同,则返回NULL。
而除数为NULL是可以正常处理返回NULL。
所以,解决方法:
page_rpm = earnings / NULLIF(page_views, 0)
阿斌
Read more posts by this author.
扫一扫关注微信公众号:耿直的IT男阿斌
聊一聊IT男眼中的世界
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK