with cte as ( SELECT c.name 'Соревнование', u.id 'Секция', pc.name 'Категория туриста' FROM competition c INNER JOIN competition_member cm on c.id = cm.Competition_id INNER JOIN person p on cm.Person_id = p.id INNER JOIN group_persons gp on p.id = gp.Person_id INNER JOIN `group` g on gp.Group_id = g.id INNER JOIN unit u on g.Unit_id = u.id INNER JOIN person_category pc on p.Category_id = pc.id WHERE u.id = 72 and pc.name = 'Спортсмен' ) select cte.* from cte union select 'Общее количество', count(*), '' from cte;
Обсуждают сегодня