例子如下:
abc表有两个列值:“ID”(自动编号)和“值”。
其中“值”的取值为字符“0”和“1”的随机排列。数据10W个.
“值”排列【示例1】01011000101101111110111
统计规则如下:
1.
统计对象判断-排列与“000”(就是出现连续三个0的情况)相吻合的情况,结果有“是”“非”两种情况。
其中“是”的情况为:【示例1】的第一个字符(注:得出“是”“非”结果之后的后面第一个字符)“0”与“000”的第一个字符对比,它们相符,则判断为“是”,该轮判断结束。紧接着取后面的第一个值“1”与“000”的第一个字符对比,它们不相符,这时就取“1”后面的值“0”与“000”的第二个字符对比,它们相符,则判断为“是”.如此类推,当第三个取值依旧与“000”的第三个字符不相符时判断为“非”。
【示例1】
0 10 110 0 0 10 110 111 111 0 111
是是 是 是 是 是 是 非 非 是 非2.
统计的级数:
1级-起始级数,
2级
3级
4级
5级
6级
7级
8级
9级
10级
11级
12级
根据统计规则1,当判断结果为“非”时,上升一级。
根据统计规则1,当某级数的判断结果为“是”达5次(按级数累计)时,下降一层{第一级不适合此规则}。
当级数刚刚上升到12级时,第一轮统计结束。从下一个字符开始,进行第二轮统计,结果与前面的统计结果累加。3.
统计的对象1--累加统计各个级数中出现的“非”的次数(分级显示)。
统计的对象2--统计到达第12级的次数。
====求教!
abc表有两个列值:“ID”(自动编号)和“值”。
其中“值”的取值为字符“0”和“1”的随机排列。数据10W个.
“值”排列【示例1】01011000101101111110111
统计规则如下:
1.
统计对象判断-排列与“000”(就是出现连续三个0的情况)相吻合的情况,结果有“是”“非”两种情况。
其中“是”的情况为:【示例1】的第一个字符(注:得出“是”“非”结果之后的后面第一个字符)“0”与“000”的第一个字符对比,它们相符,则判断为“是”,该轮判断结束。紧接着取后面的第一个值“1”与“000”的第一个字符对比,它们不相符,这时就取“1”后面的值“0”与“000”的第二个字符对比,它们相符,则判断为“是”.如此类推,当第三个取值依旧与“000”的第三个字符不相符时判断为“非”。
【示例1】
0 10 110 0 0 10 110 111 111 0 111
是是 是 是 是 是 是 非 非 是 非2.
统计的级数:
1级-起始级数,
2级
3级
4级
5级
6级
7级
8级
9级
10级
11级
12级
根据统计规则1,当判断结果为“非”时,上升一级。
根据统计规则1,当某级数的判断结果为“是”达5次(按级数累计)时,下降一层{第一级不适合此规则}。
当级数刚刚上升到12级时,第一轮统计结束。从下一个字符开始,进行第二轮统计,结果与前面的统计结果累加。3.
统计的对象1--累加统计各个级数中出现的“非”的次数(分级显示)。
统计的对象2--统计到达第12级的次数。
====求教!
解决方案 »
- sql2000 多表查询
- 这句存储过程是什么意思?
- 功能就像SQLServer里面Profiler一样的工具, 针对Oracle的是啥工具?
- job不能自動執行
- 求一考勤的存储过程(100分)
- [DBNETLIB][ConnectionOpen(Connect()).]SQL.Server不存在或拒绝访问!
- 一个表的外键一定是另一个表的主键吗?
- 表中关键字的问题,请大虾多多指点?
- 登录问题
- 在WIN98下用VB6。0和SQLOLEDB能访问SQLSERVER7桌面版的数据库而用SQLOLEDB访问SQLSERVER200桌面版却不能的问题
- 请问 SQL05 Express 主要缺点是什么?
- 到时间自动执行程序?
上面例子在execl可以用编程实现。
(
id int identity,
tmp varchar(40)
)declare @iStr varchar(30)
,@i int
,@j intset @i = 1
set @j = 1
set @iStr = ''while @i <=100
begin
while @j <=30
begin
select @iStr = @iStr + cast(cast(rand()*100 as int)%2 as varchar(1))
set @j=@j+1
end
insert into tmp_t(tmp)
select @iStr
set @iStr=''
set @j=1
set @i =@i+1
end--truncate table tmp_t
--select * from tmp_tselect identity(int,1,1) as id,replace(replace(replace(tmp,'111','非'),'1',''),'0','是') as tmp
into tmp_t_2
from tmp_t--select * from tmp_t_2create table tmp_r
(
id int,
N int default 0,
Y int default 0
)insert into tmp_r(id)
select '1'
union all
select '2'
union all
select '3'
union all
select '4'
union all
select '5'
union all
select '6'
union all
select '7'
union all
select '8'
union all
select '9'
union all
select '10'
union all
select '11'
union all
select '12'GO--select * from tmp_t_2
--select * from tmp_rdeclare @i int,
@m int,
@j int,
@z varchar(4),
@str varchar(40),
@str2 varchar(20)set @i = 1
set @m = 0
set @j = 1
set @str2 = ''while @j <= (select count(1) from tmp_t_2)
begin
select @str = tmp from tmp_t_2 where id = @j
while len(@str)>0
begin
set @z = left(@str,1)
if @z = '非'
begin
if @i <12
begin
update tmp_r set N = N + 1 where id = @i
set @i = @i +1
end
else
begin
update tmp_r set N = N + 1 where id = 12
set @i = 1
end
end
else if @z = '是'
begin
select @m = Y from tmp_r where id = @i
set @str2 = @str2+'是'
if len(@str2)= 5
begin
update tmp_r set Y=0 where id =@i
if @i>1
begin
set @i = @i -1
end
set @str2 = ''
end
else if (@m+len(@str2))=5
begin
update tmp_r set Y=0 where id =@i
if @i>1
begin
set @i = @i -1
end
set @str2 = ''
end
else if (@m+len(@str2))<5
begin
update tmp_r set Y = (@m+len(@str2)) where id =@i
end
end
set @str = stuff(@str,1,1,'')
end
set @j = @j +1
endselect * from tmp_r GOdrop table tmp_t
drop table tmp_t_2
drop table tmp_rresult:
--------------
1 108 4
2 51 0
3 19 3
4 13 0
5 10 0
6 5 0
7 5 0
8 5 0
9 0 0
10 0 0
11 0 0
12 0 0
1、是否在出现一个'非'以后才累计'是'的个数?
2、出现'非'以后因为'是'的个数很多再次回到1级,而此刻再次出现是是否累加?例:'非是是是是是是是非是是是'的等级是2还是1?另:'非是是是是是是是是是是是是非非是是是'是1、2还是3?
12等级出现次数需要明确上面两个问题才好计算
declare @data varchar(8000)
declare @isnotlist varchar(8000)
declare @notcount int
set @data='01011000101101111110111'
--是非排列
set @isnotlist=replace(replace(replace(@data,'111','非'),'1',''),0,'是')
print @isnotlist
--'非'总数计算
set @notcount=len(replace(@isnotlist,'是',''))
print @notcount
--统计达到12级的次数
set @outtime=0
set @i=1
set @level=1
while @i<=len(@isnotlist)
begin
set @level=@level+(case substring(@isnotlist,@i,1) when '是'
then -0.2*(case @level when 1 then 0 else 1 end) else 1 end)
if CEILING(@level)=12
begin
set @level=1
set @outtime=@outtime+1
end
end
print @outtime
数据从已有的数据库A下的表B 的字段C的值读取呢?以便检验程式
谢谢!