SQL Query to Group Records in MS-ACCESS

1
Hello, I would like a command in SQL for a query in an Access database. The structure of the table is:
tbList

Id | Nome | Genero | Endereco | Estado | ...

The result you would like to group by state and count the number of gender (sex) this way:

+-----------+----------+-----------+
| ESTADO    | FEMININO | MASCULINO |
+-----------+----------+-----------+
| SP        |       36 |        40 |
| RJ        |       44 |        13 |
| MG        |       17 |        23 |
...
...

Thank you in advance for the attention of everyone!

PS: Sorry for anything wrong that I did, but I'm still learning to use stackoverflow !

    
asked by anonymous 19.09.2018 / 15:49

1 answer

1

I think this syntax is accepted in MS-ACCESS :

SELECT      Estado
        ,   SUM(IIF(Genero = 'F', 1, 0)) AS FEMININO
        ,   SUM(IIF(Genero = 'M', 1, 0)) AS MASCULINO
FROM        tbList
GROUP BY    Estado

I assumed that in the Genero column were the values 'F' and 'M' , otherwise just change to the actual values.

    
19.09.2018 / 15:56