select case when id in (1,2,3,4) then 'Начальная школа'
when id in (5,6,7,8,9) then 'Средняя школа'
when id in (10,11) then 'Старшая школа'
end Class_type,
COUNT(*), sum(case when s.ocenka>4 then 1 end as) 'Отличники' from class c
group by Class_type
COUNT(*)
SELECT
case when id in (1,2,3,4) then 'Начальная школа'
when id in (5,6,7,8,9) then 'Средняя школа'
when id in (10,11) then 'Старшая школа'
end AS Class_type,
(
SELECT COUNT(*)
FROM class cc
WHERE (
case when сс.id in (1,2,3,4,5) then 'Начальная школа'
when cc.id in (6,7,8,9) then 'Средняя школа'
when cc.id in (10,11) then 'Старшая школа'
) = (
case when c.id in (1,2,3,4) then 'Начальная школа'
when c.id in (5,6,7,8,9) then 'Средняя школа'
when c.id in (10,11) then 'Старшая школа'
)
),
SUM(case when s.ocenka>4 then 1 end) AS 'Отличники'
FROM class c
GROUP BY Class_type
select Class_type,
count(1) over (partition by case when Class_type = 'HZ' then 'Начальная школа' else Class_type end) cnt,
sum(for_sum) over (partition by case when Class_type = 'HZ' then 'Средняя школа' else Class_type end) sum_
from (
select case when id in (1,2,3,4) then 'Начальная школа'
when id = 5 then 'HZ'
when id in (6,7,8,9) then 'Средняя школа'
when id in (10,11) then 'Старшая школа'
end Class_type,
case when s.ocenka>4 then 1 else 0 end for_sum
from class c ) t
group by Class_type
having Class_type <> 'HZ'