Sampling and error counting in a generic zipcode

I have a table below

ID NAME AGE ZIPCODE
1  A    29   321345
2  B    25   321375
....

etc. about 40 thousand records.

I want to get individual zipcodes up to just four digits.

like 3213 * include like (321345 || 321375) .

So, is there a similar suggestion like GROUP BY for this?

+4
source share
1 answer

If only single zipcodes (4-bit) are needed, use this:

SELECT DISTINCT LEFT(zipcodes, 4) ZIPCODE_4_DIGIT FROM tbl

If frequency is also needed, use another:

SELECT LEFT(zipcodes, 4) ZIPCODE_4_DIGIT, COUNT(1) FREQUENCY 
FROM tbl
GROUP BY ZIPCODE_4_DIGIT;
+3
source

Source: https://habr.com/ru/post/1629358/


All Articles