• Сколько M и W в каждом департаменте
  • Максимальное количество в одном департаменте

 

# id, dep, s
'1', '1', 'm'
'2', '1', 'm'
'3', '1', 'w'
'4', '2', 'm'
'5', '3', 'm'

 

 

select *
from (
 SELECT dep, count(dep) as c ,s FROM vn_test.new_vn_test  where s ='w'   group by dep  -- HAVING c = "m" 
    UNION   ALL
 SELECT dep, count(dep) as c ,s FROM vn_test.new_vn_test  where s ='m'  group by dep --  HAVING c = "m"  ;
) as a
order by dep asc

 

  
select if (1>2,"a","r"); 
SELECT REPLACE("ABC ABC ABC", "A", "B"); 
 #> 'BBC BBC BBC'

 

 

 

 


 

select dep, count(case when s=’m’ then 1 else NULL end), count(case when s=’w’ then 1 else NULL end) FROM table GROUP BY dep

select dep, cnt FROM (select dep, count(1) cnt FROM table GROUP by dep ORDER by cnt DESC) p LIMIT 1