Wallace Mogerty
Wallace Mogerty

Reputation: 335

SQL: Select First Letter of Column Where That Letter Occurs Specific Number of Times

I have an assignment where I am to run the following select query: "Considering only the students for whom some information is missing, what letter occurs 8 times as the first letter of the last name of such a student?"

The query I have thus far is below, but it is giving an error that there is a syntax error at or near "LEFT":

SELECT LEFT(last, 1)
FROM hogwarts_students
WHERE COUNT LEFT(last, 1) = 8 
AND finish IS NULL;

Upvotes: 1

Views: 474

Answers (1)

McNets
McNets

Reputation: 10807

Aggregate functions require a GROUP BY clause in some DBMS.

SELECT LEFT(last, 1)
FROM hogwarts_students
WHERE finish IS NULL 
GROUP BY LEFT(last, 1) 
HAVING COUNT (*) = 8;

Upvotes: 2

Related Questions