I'll-Be-Back
I'll-Be-Back

Reputation: 10828

numbers into group?

In the database table, I have about 1 million record.

In the number field there are about 11 digits number.

If the 5 digit number is the same, I want to group it so I can export it later.

How to archive this?

For example:

077129342480

074545344535

077127777476

077126565656

074546546654

You can see there are two group of number which are 07712 and 07454

In the group field I could declare the group name in number?

Upvotes: 0

Views: 88

Answers (3)

themhz
themhz

Reputation: 8424

select LEFT(data, 5) Groupnumber, count(id)
from test
group by Groupnumber;

Upvotes: 1

xdazz
xdazz

Reputation: 160833

You can try GROUP BY SUBSTR(number, 1, 5) or GROUP BY LEFT(number, 5).

Upvotes: 1

Oleg Dok
Oleg Dok

Reputation: 21756

select SUBSTR(number, 1, 5) Groupnumber, number
from yourtable

Upvotes: 1

Related Questions