Practice Joins -- Multiple Tables with REBU Q8

For Q8 at this link:
https://www.codecademy.com/paths/analyze-data-with-sql/tracks/analyze-data-sql-join-data/modules/analyze-data-sql-practice-joins/projects/querying-tables

While my code runs sucessfully until selecting rows less than 500.
WITH riderss AS (
SELECT *
FROM riders
UNION
SELECT *
FROM riders2
)
SELECT SUM(riderss.total_trips) AS ‘#_of_trips’, riderss.id
FROM riderss
WHERE riderss.#_of_trips < 500
GROUP BY 2
ORDER BY 1;

Codes fail after add constraint of “WHERE riderss.#_of_trips <500”
Does it break any rules?

Many Thx for helping~

@script5533450681 Welcome to the forums! This may be nothing, but do you need riderss.id in parentheses as well?

To the best of my knowledge, you cannot use a field alias - in your case #_of_trips - in your WHERE clause.

If you wanted to restrict the query to only return rows where the total number of trips is below 500, you would need to repeat your SUM:

WITH riderss AS (
SELECT *
FROM riders
UNION
SELECT *
FROM riders2
)
SELECT SUM(riderss.total_trips) AS ‘#_of_trips’, riderss.id
FROM riderss
WHERE SUM(riderss.total_trips) < 500
GROUP BY 2
ORDER BY 1;

I think that will do what you’re after.