必须加入辅助列,如ID,自增
TRY:
SELECT d.*, c.tt
FROM (select a.bg,a.js,format(count(*),'0000') as tt from
(select bg,js from (
SELECT partition(id,1,
(SELECT COUNT(*) FROM 表1),3), mid(trim(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),1,INSTR(TRIM(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),':')-1) AS bg, trim(mid(trim(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),
INSTR(TRIM(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),':')+1,
len(str(id)))) AS js, *
FROM 表1
) group by bg,js ORDER BY VAL(BG),VAL(JS)) a
left join
(select bg,js from (
SELECT partition(id,1,
(SELECT COUNT(*) FROM 表1),3), mid(trim(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),1,INSTR(TRIM(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),':')-1) AS bg, trim(mid(trim(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),
INSTR(TRIM(partition(id,1,(SELECT COUNT(*) FROM 表1),3)),':')+1,
len(str(id)))) AS js, *
FROM 表1
) group by bg,js ORDER BY VAL(BG),VAL(JS)) b
on VAL(a.js)>=VAL(b.js)
group by a.bg,a.js
ORDER BY VAL(A.BG),VAL(A.JS)) AS c LEFT JOIN 表1 AS d ON (d.id BETWEEN val(c.js) AND val(c.bg))
ORDER BY ID;
[此贴子已经被作者于2006-10-3 15:39:13编辑过]
|