Мне нужно вывести id компании вместе с максимальных смен ее руководителей за дату. Вторую часть я сделал, но у меня не получается чтобы отображался id. Вот запрос
select max(total) from (select consolidation_of_the_head.id_subdivision as fak, count(consolidation_of_the_head.nomer) as total from consolidation_of_the_head where consolidation_of_the_head.data between '2002-04-04' and '2022-06-27' group by consolidation_of_the_head.id_subdivision) as result ;
Надо чтобы было еще и отображение самого id рядом с max.
Используя запрос
select consolidation_of_the_head.id_subdivision as fak, count(consolidation_of_the_head.nomer) as total from consolidation_of_the_head where consolidation_of_the_head.data between '2002-04-04' and '2022-06-27' group by consolidation_of_the_head.id_subdivision order by count(consolidation_of_the_head.nomer)
select consolidation_of_the_head.id_subdivision as fak, count(consolidation_of_the_head.nomer) as total from consolidation_of_the_head where consolidation_of_the_head.data between '2002-04-04' and '2022-06-27' group by consolidation_of_the_head.id_subdivision order by count(consolidation_of_the_head.nomer) limit 1