This challenge is all about counting the number of occurrence of characters in a string using a SET based query. The task is to list all the characters and count of that character within the given string.
Data Chars NumberOfOccurance
---- ----- -------------------
12 1 1 appears (1) times
12 2 2 appears (1) times
xx x x appears (2) times
- Results must be sorted in ascending order of Data and then by Character.
- The output should be in the same way as it has been shown.
Use the following scripts to generate the sample data for this challenge.
DECLARE @T TABLE(Data VARCHAR(MAX))
INSERT INTO @T
SELECT '12' UNION ALL
SELECT * FROM @T
- The solution should be a single query that starts with a "SELECT" or “;WITH”.
Puzzles, TSQL Beginners Challenge, TC, TSQL Beginners Challenge 14