英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论