1

This is the select statement that I'm trying to use, and I'm trying to pull the count of all records that start with the phrase Unknown, but I'm getting an incorrect syntax error near the closing parenthesis of the count. How can I use count in this way?

SELECT DISTINCT [ID], COUNT(ID), COUNT([NAME] LIKE 'Unknown%')
FROM table.foo
GROUP BY [ID]
1
  • Put the condition in a Where clause. Commented Oct 2, 2017 at 14:01

1 Answer 1

6

You don't need SELECT DISTINCT with GROUP BY. Just use a CASE as the argument to SUM():

SELECT ID, COUNT(ID), 
       SUM(CASE WHEN NAME LIKE 'Unknown%' THEN 1 ELSE 0 END)
FROM table.foo
GROUP BY ID;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.