不等号运算符无法解析布尔和整数数据类型。

huangapple go评论77阅读模式
英文:

Inequality operator cannot resolve boolean and int datatype

问题

I have a table Neg_days containing 4 columns,
Account number(long), days_neg(int), days_pos(int), days_neg_pos(int).
The latter 3 columns have mostly null values and one row containing zeroes.

When I try to perform the comparison operator:

spark.sql = """
select nd.account_number
 , case when days_neg > days_pos > days_neg_pos then 1 else 0 end as new_column
from Neg_days as nd
"""
spark.sql.createOrreplaceTempView("Accounts_down")

The error thrown is:

couldnt resolve the (days_neg > days_pos > days_neg_pos) due to datatype mismatch.
Couldnt resolve bool and int

I have already changed the datatype to int so I can't understand where the bool datatype is coming from.

英文:

I have a table Neg_days containing 4 columns,
Account number(long), days_neg(int), days_pos(int), days_neg_pos(int).
The latter 3 columns have mostly null values and one row contatining zeroes.

When I try to perform the comparison operator:

spark.sql ="""
select nd.account_number
 , case when days_neg > days_pos > days_neg_pos then 1 else 0 end as new_column
from Neg_days as nd
"""
spark.sql.createOrreplaceTempView("Accounts_down")

The error thrown is:

couldnt resolve the (days_neg > days_pos > days_neg_pos) due to datatype mismatch.
Couldnt resolve bool and int 

I have already changed the datatype to int so I cant understand where the bool datatype is coming from

答案1

得分: 1

布尔数据类型来自比较操作。SQL 不同于 Python,不能像 A > B > C 这样使用快捷方式。这将被解释为 (A > B) > C。如果 A、B 和 C 是整数,最终会得到 bool > int,因此会出现错误。相反,你需要编写 A > B AND B > C

英文:

The boolean datatype comes from the comparison operation. SQL is not Python and you cannot have shortcuts like A > B > C. This will be evaluated as (A > B) > C. If A, B, and C are integers, you end up with bool > int and hence the error. Instead, you need to write A > B AND B > C.

huangapple
  • 本文由 发表于 2023年4月13日 15:29:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76002746.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定