By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE table1
(`ID` varchar(40))
;
INSERT INTO table1
(`ID`)
VALUES
('007eefab-5f77-4584-b41c-db09785c6e52'),
('''0138ba80-47ad-414a-bcea-65f0ca165a2a'),
('022f1261-32e7-4870-bc29-2fc770260bc2'),
('02d756dc-c6ca-446a-a17a-ab52b1341595'),
('03a8242b-0d6f-4680-9890-b90e53d46f89'),
('03c56406-91f0-4c25-9d07-a4c91df565e5'),
('0521cabb-94de-4186-ae8e-07e11b8de01f'),
('06e24fc0-5dc7-4b0b-9797-93964d22f5de'),
('0822c7fb-ebe9-43cd-8f0e-df7fda50f711'),
('09353ab2-6e17-4948-868c-a617977f3902'),
('0a11a144-6e88-106d-9ba2-105a00000028'),
('0a11a144-6e88-106d-9ba2-11060000002a'),
('0a11a144-6e88-106d-9ba2-11970000002c'),
('0a11a144-6e88-106d-9ba2-12120000002f'),
('0a11a144-6e88-106d-9ba2-4fb40000005f'),
('0a11a144-6e88-106d-9ba2-4fbd00000060'),
('0a11a144-6e88-106d-9ba2-506100000067'),
('0a11a144-6e88-106d-9ba2-56cf0000006d'),
('0a11a144-6e88-106d-9ba2-57b200000073'),
('0a11a144-6e88-106d-9ba2-580100000077'),
('0a11a144-6e88-106d-9ba2-580d00000078'),
('0a11a144-6e88-106d-9ba2-581100000079'),
('0a11a144-6e88-106d-9ba2-5b440000008c'),
('0a11a144-6e8d-190f-9ba3-64fe00000001'),
('0a11a144-6e8d-190f-9ba3-683100000010'),
('0a11a144-6e8d-190f-9ba3-68b20000001a'),
('0a11a144-6e8d-190f-9ba3-68e20000001e'),
('0a11a144-6e8d-190f-9ba3-691700000020'),
SELECT
MIN(ID), MAX(ID), COUNT(*), nt
FROM
(SELECT
`ID`,
IF(@countr < @div2, @ntile, @ntile:=@ntile + 1) AS nt,
IF(@countr < @div2, @countr:=@countr + 1, @countr:=1) c1,
IF(@ntile <= CAST(@mod AS UNSIGNED), @div2:=@div + 1, @div2:=@div) div2
FROM
(SELECT
ID, @mod:=countr % 16, @div:=countr DIV 16, @div2:=@div
FROM
table1, (SELECT
COUNT(*) countr
FROM
table1, (SELECT @ntile:=1, @countr:=0, @div2:=0) t3) t2) t1
ORDER BY ID) t1
GROUP BY nt
ORDER BY CAST(nt AS UNSIGNED);
MIN(ID) | MAX(ID) | COUNT(*) | nt |
---|---|---|---|
'0138ba80-47ad-414a-bcea-65f0ca165a2a | 022f1261-32e7-4870-bc29-2fc770260bc2 | 3 | 1 |
02d756dc-c6ca-446a-a17a-ab52b1341595 | 03c56406-91f0-4c25-9d07-a4c91df565e5 | 3 | 2 |
0521cabb-94de-4186-ae8e-07e11b8de01f | 0822c7fb-ebe9-43cd-8f0e-df7fda50f711 | 3 | 3 |
09353ab2-6e17-4948-868c-a617977f3902 | 0a11a144-6e88-106d-9ba2-11060000002a | 3 | 4 |
0a11a144-6e88-106d-9ba2-11970000002c | 0a11a144-6e88-106d-9ba2-4fb40000005f | 3 | 5 |
0a11a144-6e88-106d-9ba2-4fbd00000060 | 0a11a144-6e88-106d-9ba2-56cf0000006d | 3 | 6 |
0a11a144-6e88-106d-9ba2-57b200000073 | 0a11a144-6e88-106d-9ba2-580d00000078 | 3 | 7 |
0a11a144-6e88-106d-9ba2-581100000079 | 0a11a144-6e8d-190f-9ba3-64fe00000001 | 3 | 8 |
0a11a144-6e8d-190f-9ba3-683100000010 | 0a11a144-6e8d-190f-9ba3-68e20000001e | 3 | 9 |
0a11a144-6e8d-190f-9ba3-691700000020 | 0a11a144-6e8d-190f-9ba4-b201000001c4 | 3 | 10 |
0a11a144-6e8d-190f-9ba4-b290000001cc | 0a348078-58fd-12fd-963f-86fa000008a2 | 3 | 11 |
0a348078-58fd-12fd-9640-24f000000c9d | 0a348078-58fd-12fd-9641-ba92000649b0 | 3 | 12 |
0a348078-58fd-12fd-9641-dc9800070215 | 0a348078-58fd-12fd-9641-e05900070345 | 2 | 13 |
0a348078-58fd-12fd-9641-e0bf00070351 | 0a348078-58fd-12fd-9642-bcfe00099496 | 2 | 14 |
0a348078-58fd-12fd-9644-06b9000c1f04 | 0a348078-5911-1bfe-9645-4b370000032a | 2 | 15 |
0a348078-5916-1f0d-9646-94da00001308 | 0a348078-5916-1f0d-9649-2cfa00053e55 | 2 | 16 |
select
min(ID)
, max(ID)
,count(*)
, nt
from
( select
ID
, ntile(16) over (order by ID) nt
from table1) t1
group by nt order by nt;
min(ID) | max(ID) | count(*) | nt |
---|---|---|---|
'0138ba80-47ad-414a-bcea-65f0ca165a2a | 022f1261-32e7-4870-bc29-2fc770260bc2 | 3 | 1 |
02d756dc-c6ca-446a-a17a-ab52b1341595 | 03c56406-91f0-4c25-9d07-a4c91df565e5 | 3 | 2 |
0521cabb-94de-4186-ae8e-07e11b8de01f | 0822c7fb-ebe9-43cd-8f0e-df7fda50f711 | 3 | 3 |
09353ab2-6e17-4948-868c-a617977f3902 | 0a11a144-6e88-106d-9ba2-11060000002a | 3 | 4 |
0a11a144-6e88-106d-9ba2-11970000002c | 0a11a144-6e88-106d-9ba2-4fb40000005f | 3 | 5 |
0a11a144-6e88-106d-9ba2-4fbd00000060 | 0a11a144-6e88-106d-9ba2-56cf0000006d | 3 | 6 |
0a11a144-6e88-106d-9ba2-57b200000073 | 0a11a144-6e88-106d-9ba2-580d00000078 | 3 | 7 |
0a11a144-6e88-106d-9ba2-581100000079 | 0a11a144-6e8d-190f-9ba3-64fe00000001 | 3 | 8 |
0a11a144-6e8d-190f-9ba3-683100000010 | 0a11a144-6e8d-190f-9ba3-68e20000001e | 3 | 9 |
0a11a144-6e8d-190f-9ba3-691700000020 | 0a11a144-6e8d-190f-9ba4-b201000001c4 | 3 | 10 |
0a11a144-6e8d-190f-9ba4-b290000001cc | 0a348078-58fd-12fd-963f-86fa000008a2 | 3 | 11 |
0a348078-58fd-12fd-9640-24f000000c9d | 0a348078-58fd-12fd-9641-ba92000649b0 | 3 | 12 |
0a348078-58fd-12fd-9641-dc9800070215 | 0a348078-58fd-12fd-9641-e05900070345 | 2 | 13 |
0a348078-58fd-12fd-9641-e0bf00070351 | 0a348078-58fd-12fd-9642-bcfe00099496 | 2 | 14 |
0a348078-58fd-12fd-9644-06b9000c1f04 | 0a348078-5911-1bfe-9645-4b370000032a | 2 | 15 |
0a348078-5916-1f0d-9646-94da00001308 | 0a348078-5916-1f0d-9649-2cfa00053e55 | 2 | 16 |