I have a table that holds subscription information. Some of the mailing zip codes are five digits, while some are 9 (55025 vs. 55025-4056). I want to run a query to count the total subscriptions in each zip code, but need to group the 9 digit ones with the 5 digit ones where they match.
SELECT zip, COUNT(id) AS total FROM subscriptions WHERE status = 'A' GROUP BY zip
But obviously it reads 55025 and 55025-4056 as two different zip codes. If 55025 has 100 records and 55025-4056 has 10 records, I would like for the result to show 55025 = 110 records. How can I perform this query to group by the first 5 digits of the zip code?
Thanks
1 Answer