FORUM Marketing Analytics Getting an error

Getting an error

From Exercise 66:

Let’s practice our newly learned skill of grouping and counting. Which email domain has the most amount of users at Bindle?

I am writing a code other way, by forming function. I am getting error. Could anyone help me to identify where I have mistaken?

WITH domain AS (
  SELECT
    SPLIT_PART (email, '@', 2) AS email_domain,
    FROM users
)

SELECT
  email_domain,
  COUNT(*)
FROM domain
GROUP BY 1
ORDER BY 2 DESC

REPLIES

Hi @sagar 👋

If I’m not mistaken, you should see the following error message:

syntax error at or near "FROM" (scan.l:1230)

The DB engine tries to tell us that something isn’t right around one of the two FROM statements we have.

In my experience, this error most often appears when we have a hanging comma. Maybe you’ve deleted one of the columns from the SELECT statement and now comma from previous column is hanging.

If you look at your CTE, there’s a hanging comma after the email column:

email_domain,

If you remove it, the query works like a charm.

Hope that helps 😊 Have a great day, @sagar 🚀

WRITE A REPLY