user889349 user889349 - 3 months ago 7
MySQL Question

Group request from mysql

I have a table with ZIP codes and country state. For example:

zip state d1 d2
99501 AK 0.00 0.00
99502 AK 0.00 0.00
99503 AK 0.00 0.00
36513 AL 0.04 0.04
36518 AL 0.04 0.04


I'm trying to group states and count number of ZIP in each state:

SELECT
*
FROM
`#taxes`
GROUP BY
`state`


How can I do this? Thanks!

Answer

Like this:

SELECT 
    state, count(distinct zip)
FROM 
  `#taxes`
GROUP BY
   state
Comments