How do I a query in SQL Server using T-SQL to return the counts of the first letter/character in a column's values?
Asked
Active
Viewed 3,932 times
-2
-
1The proper way would be to ask a question and then add an answer and accept it. Perhaps think of editing your post? – Andrzej Bobak Nov 12 '13 at 16:27
-
Ok, I changed it. Thanks for the advice. What do you mean by "accept think"? – Robert Bernstein Nov 12 '13 at 16:29
-
But that's for Oracle. I changed it to T-SQL (for SQL Server). Would you just add mine as a comment to that post? – Robert Bernstein Nov 12 '13 at 16:31
-
1"think" -> "it". A common typo ;) – Andrzej Bobak Nov 12 '13 at 16:41
-
3[A SQL Server specific dupe does already exist too](http://stackoverflow.com/questions/13500638/sql-how-many-records-start-with-the-same-letter) – Martin Smith Nov 12 '13 at 16:41
1 Answers
5
SELECT SUBSTRING(FileName, 1, 1) as first_letter, COUNT(FileId)
FROM Files
GROUP BY SUBSTRING(FileName,1,1)
ORDER BY first_letter
I modified an example for Oracle that can be found here: group by first character

Community
- 1
- 1

Robert Bernstein
- 783
- 12
- 18