M
M
magaomarov20132018-12-16 03:24:14
SQL
magaomarov2013, 2018-12-16 03:24:14

How to select elements in sql server that have 3 or more vowels?

Here is the task:
Add to the created table teachers whose last names contain 3 or
more vowels
.
I need to somehow implement this through like , but I don’t know how to register it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
basrach, 2018-12-16
@basrach

DECLARE @teachers TABLE ([LastName] NVARCHAR(255) NOT NULL);
INSERT INTO @teachers
VALUES
(N'Холстинин'),
(N'Пирожков'),
(N'Пугачева'),
(N'Цой');

DECLARE @vowels TABLE ([Letter] NCHAR(1) NOT NULL);
INSERT INTO @vowels VALUES
(N'а'),
(N'о'),
(N'и'),
(N'е'),
(N'ё'),
(N'э'),
(N'ы'),
(N'у'),
(N'ю'),
(N'я');

SELECT [t].[LastName]
FROM @teachers [t]
CROSS JOIN @vowels [v]
GROUP BY [t].[LastName]
HAVING SUM(LEN([t].[LastName]) - LEN(REPLACE([t].[LastName], [v].[Letter], ''))) > 3;

V
Vladimir Malin, 2018-12-20
@Vmalin

Sorry. one inaccuracy: ''))) > =3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question