cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

I am new to Databricks and SQL. My CASE statement is not working and I cannot figure out why. Below is my code and the error message I'm receiving. Grateful for any and all suggestions. I'm trying to put yrs_to_mat into buckets.

am777
New Contributor
SELECT *, yrs_to_mat,
 CASE 
      WHEN < 3 THEN "under3"
      WHEN => 3 AND < 5 THEN "3to5"
      WHEN => 5 AND < 10 THEN "5to10"
      WHEN => 10 AND < 15 THEN "10to15"
      WHEN => 15 THEN "over15"
      ELSE null END AS maturity_bucket
FROM matyrs; 
Error in SQL statement: ParseException: 
[PARSE_SYNTAX_ERROR] Syntax error at or near 'THEN'(line 3, pos 15)
 
== SQL ==
SELECT *, yrs_to_mat,
 CASE 
      WHEN < 3 THEN "under3"
---------------^^^
      WHEN => 3 AND < 5 THEN "3to5"
      WHEN => 5 AND < 10 THEN "5to10"
      WHEN => 10 AND < 15 THEN "10to15"
      WHEN => 15 THEN "over15"
      ELSE null END AS maturity_bucket
FROM matyrs

1 REPLY 1

Pat
Honored Contributor III

Hi @Anne-Marie Wood​ ,

I think it's more SQL general issue:

you are not comparing any value to `< 3`

it should be something like :

WHEN X < 3 THEN "under3"

    SELECT *, yrs_to_mat,
     CASE 
          WHEN X < 3 THEN "under3"
          WHEN X => 3 AND < 5 THEN "3to5"
          WHEN X => 5 AND < 10 THEN "5to10"
          WHEN X => 10 AND < 15 THEN "10to15"
          WHEN X => 15 THEN "over15"
          ELSE null END AS maturity_bucket
    FROM matyrs; 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.