SQL Server Inequality operator cannot resolve boolean and int datatype

rbl8hiat  于 2023-04-19  发布在  其他
关注(0)|答案(1)|浏览(79)

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

smtd7mpg

smtd7mpg1#

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 .

相关问题