Given a word, write a SQL query to find and display the distinct vowels (A, E, I, O, U) present in that word.
Expected Output:
Try solving the question yourself! If you need help, click below to reveal the solution.
Given a word, write a SQL query to find and display the distinct vowels (A, E, I, O, U) present in that word.
Try solving the question yourself! If you need help, click below to reveal the solution.
DECLARE @A VARCHAR(300)='FABRICOFDATA'
DECLARE @END INT =1
DECLARE @BEGIN INT=0
DECLARE @CHECKER VARCHAR(5)
DECLARE @VOWELS VARCHAR(250)=NULL
WHILE @begin<=(SELECT LEN(@A))
BEGIN
SET @CHECKER=(SELECT SUBSTRING(@A,@Begin,@End-@Begin))
IF @CHECKER IN ('a','e','i','o','u')
BEGIN
SELECT @VOWELS= IIF(@Vowels IS NULL,'',@Vowels+',')+@checker
End
SET @BEGIN =@BEGIN+1
SET @END=@END+1
END
SELECT @A AS INPUT_STRING
SELECT STRING_AGG(VALUE,',') AS Vowels
FROM
(
SELECT DISTINCT * FROM
(
SELECT VALUE FROM string_split(@Vowels,',')
) a
)b
2Comments
great
ReplyDeleteI like these kinds of SQL puzzles because they make a technical topic feel more like a little game. Finding the distinct vowels in a word sounds simple at first, but turning that idea into a SQL challenge makes you stop and think about how you want to approach the problem. I’ve always enjoyed games where the solution isn’t immediately obvious and you have to experiment until something clicks. That same trial-and-error feeling is probably what makes puzzles like this enjoyable, whether you’re working with SQL or just looking for something different to play, such as I like these kinds of SQL puzzles because they make a technical topic feel more like a little game. Finding the distinct vowels in a word sounds simple at first, but turning that idea into a SQL challenge makes you stop and think about how you want to approach the problem. I’ve always enjoyed games where the solution isn’t immediately obvious and you have to experiment until something clicks. That same trial-and-error feeling is probably what makes puzzles like this enjoyable, whether you’re working with SQL or just looking for something different to play, such as FFBET.
ReplyDelete.