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条答案
按热度按时间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 withbool > int
and hence the error. Instead, you need to writeA > B AND B > C
.