如何取得某字段内容连续相同的次数?
如表A:
ID Value
----- -------
1 AB
2 BC
3 BC
4 AB
5 BC
6 BC
7 BC
8 AB
9 AB
10 DE我如何取得Value字段里,BC值连续出现的最大次数是3?AB值连续出现的最大次数是2?
如表A:
ID Value
----- -------
1 AB
2 BC
3 BC
4 AB
5 BC
6 BC
7 BC
8 AB
9 AB
10 DE我如何取得Value字段里,BC值连续出现的最大次数是3?AB值连续出现的最大次数是2?
解决方案 »
- 问个简单的关于联合查询再插入的问题?
- 关于不建立临时表统计每月的销售额的实现方法(符带我的做法)
- 那位高手知道如何把一個存儲過程 設置成類型系統存儲過程d得???(內詳)
- 高分请教关于Join这种SQL的用法
- 多表查询的问题
- group by 2表 统计问题
- SQL SERVER占用PC内存问题请教?
- 怎么从两个表中拿出不重复部分的数据
- 如何将Access的数据导入SQL-server
- 用DataEnvironment建立数据环境再进行报表设计。请问要解决以下问题在DataEnvironment中如何设置SQL命令!后台数据库用的是SQL2000高分求
- 怎样把变量byte[]型数组中二进制数据插入到数据库中?
- EXCEL导入一个存在的数据库'hhh'里的‘aaa’表,使EXCEL里的数据累加到'hhh'数据库里的‘aaa’表。有什么语法可以实现?
insert into @t select 1 ,'AB'
insert into @t select 2 ,'BC'
insert into @t select 3 ,'BC'
insert into @t select 4 ,'AB'
insert into @t select 5 ,'BC'
insert into @t select 6 ,'BC'
insert into @t select 7 ,'BC'
insert into @t select 8 ,'AB'
insert into @t select 9 ,'AB'
insert into @t select 10,'DE'
select
b.Value,max(b.num) as num
from
(select
a.Value,isnull((select min(ID) from @t where ID>a.ID and Value!=a.Value)-a.ID,0) as num
from
@t a) b
group by
b.Value/*
Value num
----- -----------
AB 2
BC 3
DE 0
*/
这句不理解,能解释下吗?哪来的表b?
另外:下面的有无快捷方法:
insert into @t select 1 ,'AB'
insert into @t select 2 ,'BC'
insert into @t select 3 ,'BC'
insert into @t select 4 ,'AB'
insert into @t select 5 ,'BC'
insert into @t select 6 ,'BC'
insert into @t select 7 ,'BC'
insert into @t select 8 ,'AB'
insert into @t select 9 ,'AB'
insert into @t select 10,'DE'
另外:下面的有无快捷方法:
insert into @t select 1 ,'AB'
insert into @t select 2 ,'BC'
insert into @t select 3 ,'BC'
insert into @t select 4 ,'AB'
insert into @t select 5 ,'BC'
insert into @t select 6 ,'BC'
insert into @t select 7 ,'BC'
insert into @t select 8 ,'AB'
insert into @t select 9 ,'AB'
insert into @t select 10,'DE'--上面的语句,是插入测试数据的。
不知同样的功效,在Access数据库是如何实现?
http://community.csdn.net/Expert/topic/4772/4772017.xml?temp=.7373926