如下表:
key1 key2 time
1 01 t1
2 01 t2
3 02 t21
4 02 t22想查詢後得到下面結果 :
key1 key2 time 子序號
1 01 t1 1
2 01 t2 2
3 02 t21 1
4 02 t22 2在結果中加入子序號 , 向各位請教 !!!
解决方案 »
- 回调函数问题??
- Fastreport的问题。急。现场给分。
- 有关 IdTCPServer/IdTCPClient 收发消息的问题 ???
- 请教对象指针的问题
- FastReport运行时设计显示数据源问题
- BorCon 是不是开完了? Delphi9的消息呢?
- 请教:怎样在程序中控制Excel
- 小弟初学,寻求好点的教程,关于delphi数据库开发的。哪里能下!在线等待!!!
- 我用Delphi+Asp+Xml+Word作了一个办公自动化Word文档网络编辑系统,具有签名和盖章功能,大家可以下载试用。
- delphi 7 的无符号64位整型变量怎么表示
- 请问这句申明是什么意思?
- 用delphi7怎样实现对数据库的备份呢??
insert into #t1 values(2,'01','t2')
insert into #t1 values(3,'02','t21')
insert into #t1 values(4,'02','t22')select * from #t1
/*结果
1 01 t1
2 01 t2
3 02 t21
4 02 t22
*/select key1,key2,time,子序號=(select count(key2) from #t1 where key1<=a.key1 and key2='01') from #t1 a where a.key2='01'
union
select key1,key2,time,子序號=(select count(key2) from #t1 where key1<=b.key1 and key2='02') from #t1 b where b.key2='02' order by key1
/*结果
1 01 t1 1
2 01 t2 2
3 02 t21 1
4 02 t22 2
*/drop table #t1
select key1,key2 ,time,
[子序號]=(select count(1) from 表 where time=a.time and key1<=a.key1)
from 表 as a