Reputation: 890
SQL noob here. I am trying to learn SQL using the following guide. So here is my simple query answer for the following exercise question
SELECT the report_code, year, quarter, and temperature, where a “quarter” is “Q1”, “Q2”, “Q3”, or “Q4” reflecting months 1-3, 4-6, 7-9, and 10-12 respectively.
SELECT report_code, year, temperature,
CASE
WHEN month >=1 and month <= 3 then "Q1"
WHEN month >=4 and month <= 6 then "Q2"
WHEN month >=7 and month <= 9 then "Q3"
else "Q4"
END as Quarter
FROM station_data
I see that if I terminate the END as Quarter
statement with a ,
or ;
, then SQLiteStudio marks the query as invalid. Which is rather strange to me since the statement obviously needs to be terminated IMHO. Or more than likely I haven't understood what constitutes an SQL "statement" and when do we need to terminate it.
Upvotes: 0
Views: 96
Reputation: 1538
That's pretty common for queries to not need a semicolon when outside the SQL Shell. Generally they're needed, but not mandatory. For example, when launching a SQL query inside a Python script, it's unnecessary to end the query with ;
, because the shell doesn't need to know when it ends. Instead, in the SQL Shell, you are able to write the query piece by piece.
Upvotes: 0