有很多记录 怎样统计最后一条记录 在所有的记录中 “连续” 出现最多的次数
假如 字段 id ,第一列(varchar),第二列(varchar)。
id ,第一列,第二列。
1 3 4
2 3 5
3 3 6
4 4 6
5 5 7
6 3 6
7 6 5
8 2 5
9 3 6第九条数据记录 第一列的是 “3” 第二列的 是“6”
我想的到的结果是
第一列次数 第二列次数
3 2就是最后一条数据在表中在所有数据中“连续”出现最多的次数
假如 字段 id ,第一列(varchar),第二列(varchar)。
id ,第一列,第二列。
1 3 4
2 3 5
3 3 6
4 4 6
5 5 7
6 3 6
7 6 5
8 2 5
9 3 6第九条数据记录 第一列的是 “3” 第二列的 是“6”
我想的到的结果是
第一列次数 第二列次数
3 2就是最后一条数据在表中在所有数据中“连续”出现最多的次数
go
insert test select '3','4'
union all select '3','5'
union all select '3','6'
union all select '4','6'
union all select '5','7'
union all select '3','6'
union all select '6','5'
union all select '2','5'
union all select '3','6'
goselect
(select count(distinct t1.id)
from test t1,test t2
where (t2.id = t1.id +1 or t1.id = t2.id + 1) and
t1.col1 = s.col1 and t2.col1 = s.col1) as 第一列次数,
(select count(distinct t1.id)
from test t1,test t2
where (t2.id = t1.id +1 or t1.id = t2.id + 1) and
t1.col2 = s.col2 and t2.col2 = s.col2) as 第二列次数
from
(select col1,col2 from test where id = (select max(id) from test)) s--结果
第一列次数 第二列次数
3 2
--------------------
让你见笑了,应该说是试出来的才对(还不是很完善),主要用的就是相关子查询(没有特别深的知识)
这样即可select count( t1.id)
--------------
非常抱歉,ACCESS很少使用,所以就不能帮助你做转换了