- 积分
- 70
- UID
- 19819
- 阅读权限
- 20
- 注册时间
- 2015-9-14
- 精华
- 在线时间
- 小时
- 最后登录
- 1970-1-1
- 职业
- 3
|
根据楼主给出的结果,可以推测是要统计在qh有序的情况下两个kjh为包含01,02,03,04,05之间的所有kjh不是01,02,03,04,05组成的所有记录数,判断出最大值(历史最大遗漏)和距离最近包含的01,02,03,04,05的所有记录数(当前遗漏)
应该是这个意思吧,用普通sql没想到怎么处理,用mysql的存储过程写了一个统计最大值的(存储过程写的很矬,请不要嘲笑)
create table t_one(
RecNo int primary key auto_increment,
QH int unique not null,
KJH varchar(14) not null
);
-- 这个表存储了楼主截图中的数据
drop procedure if exists simpleCount;
create procedure simpleCount(out param int)
BEGIN
declare temp int default 0;
declare tempTotal int default 0;
declare tmpKjh varchar(20);
declare done int default 0;
declare rs cursor for select kjh from t_one order by qh desc;
declare continue handler for sqlstate '02000' set done=1;
open rs;
repeat
fetch next from rs into tmpKjh;
if not done then
if tmpKjh regexp '0[1-5](-0[1-5]){4}' then -- 这个正则为了判断那个无序包含01,02,03,04,05的条件
if temp >= tempTotal then
set tempTotal= temp;
set temp = 0;
end if;
else
set temp=temp+1;
end if;
end if;
until done end repeat;
close rs;
set param = tempTotal;
if temp >= tempTotal then
set param = temp;
end if;
END |
|