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;
select count(*) as 'кол-во уникальных компаний в которых есть хоть одна закрытая задача'
from Department d
join Contact c on c.DepartmentId = d.Id
where
d.Id in (
'9b90c192-60e6-df11-971b-001d60e938c6',
'66ffa487-b4da-df11-9b2a-001d60e938c6',
'2076c4b6-7fe6-df11-971b-001d60e938c6',
'b5f90312-8bc4-415a-ab4f-e311b35bf699')
and exists(
select 1 as [closed_activity]
from Activity a
where
a.OwnerId = c.Id
and a.ModifiedOn between '2018-06-01' and '2018-06-30'
and a.ResultId = '632AFDD2-F616-4EA6-87D2-8ED38EED8AFF'
)