cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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; 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group