By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE my_table(
city varchar(10),
gender varchar(2) );
insert into my_table values
('abc','m'),
('abc','f'),
('def','m');
Records: 3 Duplicates: 0 Warnings: 0
select city,sum(gender='f') as f_count,sum(gender='m') as m_count
from my_table
group by city;
city | f_count | m_count |
---|---|---|
abc | 1 | 1 |
def | 0 | 1 |