user889349 user889349 - 1 year ago 93
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 Source

Like this:

SELECT 
    state, count(distinct zip)
FROM 
  `#taxes`
GROUP BY
   state
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download