'Syntax error: Expected "(" or "," or keyword SELECT but got end of script

I just followed the query from the course but I could not figure out why I get the error message.

Syntax error: Expected "(" or "," or keyword SELECT but got end of script at [13:6]

With 
longest_used_bike AS (
    SELECT 
        Bikeid,
        SUM(duration_minutes) AS trip_duration
    FROM 
        bigquery-public-data.austin_bikeshare.bikeshare_trips
    GROUP BY 
        Bikeid
    ORDER BY 
        Trip_duration DESC
    LIMIT 1
)

Why do I get this error?



Solution 1:[1]

I had the same issue. I learned that the CTE (the WITH clause) can't work as a standalone piece of code - it is a part of a larger statement. To complete your code, you must add a SELECT statement.

Here is what I think happens:

  1. the WITH clause only creates your temporary table
  2. you need another statement to manipulate or query the temp table, a SELECT usually works.
WITH longest_used_bike AS (

SELECT
bikeid,

SUM(duration_minutes) AS trip_duration

FROM `bigquery-public-data.austin_bikeshare.bikeshare_trips`

GROUP BY
bikeid

ORDER BY trip_duration DESC
)
/* add your SELECT statement here */
SELECT *
FROM longest_used_bike;

/* or whatever else */

Solution 2:[2]

You get this error because a CTE (i.e. the WITH statement) is only part of a query. It needs to be followed by another statement, usually a SELECT.

Perhaps you intend:

With longest_used_bike AS (
      SELECT Bikeid, SUM(duration_minutes) AS trip_duration
      FROM `bigquery-public-data.austin_bikeshare.bikeshare_trips`
      GROUP BY Bikeid
      ORDER BY Trip_duration DESC
      LIMIT 1
     )
select *
from longest_used_bike;

I also assume that you are using BigQuery. The table name needs to be inclosed in backticks.

Solution 3:[3]

I also ran into this issue during the course.

From the course, written under the image of code. "If you run it now, it’ll return an error because you haven’t written any queries yet. Now, it’s time to write a query that identifies the start station that this bike came out of."

To fix the issue add another SELECT statement.

Solution 4:[4]

I ran into the same issue during the course today. By adding a SELECT statement at the end will resolve this. In this situation, we just created a temporary table without providing any query to use it in that is why we are getting this error.

You can find more about the syntax here:https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax

Solution 5:[5]

The activity has a note after the creation of the temp table that says "If you run it now, it’ll return an error because you haven’t written any queries yet. Now, it’s time to write a query that identifies the start station that this bike came out of." You just need to keep reading the activity and you will understand why errors occur.

And advice is to take a look at the activity before starting it, so you will know what you will encounter as you work through the activity.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suraj Rao
Solution 2 Gordon Linoff
Solution 3 Marcus
Solution 4 hanzo_shimada
Solution 5 Maria