I have table as below
ID NAME AGE ZIPCODE
1 A 29 321345
2 B 25 321375
....
and so on about 40K records.
I want to fetch distinct zipcodes only upto 4 digits.
like 3213* include both (321345 || 321375).
So is there any similar clause as GROUP BY for this?
If only distinct zipcodes(4-digit) is need, use this:
SELECT DISTINCT LEFT(zipcodes, 4) ZIPCODE_4_DIGIT FROM tbl
If the frequency is also needed, use another:
SELECT LEFT(zipcodes, 4) ZIPCODE_4_DIGIT, COUNT(1) FREQUENCY
FROM tbl
GROUP BY ZIPCODE_4_DIGIT;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With