zhweit 发表于 2015-9-15 11:11:47

kider 发表于 2015-9-15 12:31:10

什么个意思?怎么算遗漏?

KaIIYa 发表于 2015-9-15 15:54:28

根据楼主给出的结果,可以推测是要统计在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(-0){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
页: [1]
查看完整版本: mysql 复杂统计,当前遗漏,历史最大遗漏