请问SQL怎么给查询添加一个自动编号的字段呢?

developCpp 2006-09-06 04:25:31
例如:表 table1 (fDate,fData)
fDate , fData
--------------------
2006/2/2 , 1234
2006/5/3 , 1111
2006/7/5 , 2222
2006/8/6 , 3333
2006/8/8 , 4444
2006/9/9 , 5555

查询取值添加自动编号字段 fID
fID , fDate , fData
------------------------------------
1 , 2006/2/2 , 1234
2 , 2006/5/3 , 1111
3 , 2006/7/5 , 2222
4 , 2006/8/6 , 3333
5 , 2006/8/8 , 4444
6 , 2006/9/9 , 5555

谢谢

下面还有同样的问题,是Access的(100分)
http://community.csdn.net/Expert/topic/5003/5003145.xml?temp=.3801844
...全文
525 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwwb 2006-09-06
  • 打赏
  • 举报
回复
select fDate,fData,count(*) as fld from (
SELECT a.* from a3 a left join a3 b on a.fdate>=b.fdate)
group by fDate,fData

fuyu006 2006-09-06
  • 打赏
  • 举报
回复
create table table1 (fdate datetime,fdata varchar(4))

insert into table1
select '2006/2/2','1234'
union all
select '2006/5/3','1111'
union all
select '2006/7/5','2222'
union all
select '2006/8/6','3333'
union all
select '2006/8/8','4444'
union all
select '2006/9/9','5555'


select fid=identity(int,1,1),fdate,fdata
into #t
from table1

select * from #t

insert into #t
select '2006/8/9','6666'

select *from #t order by fid

呵呵,只会只一种方法,其它的就不知道了,期待。。。。。。。。
developCpp 2006-09-06
  • 打赏
  • 举报
回复
每天只有一条纪录
thanks very much
trying.....
fuyu006 2006-09-06
  • 打赏
  • 举报
回复
不好意思,写错了。

create table table1 (fdate datetime,fdata varchar(4))

insert into table1
select '2006/2/2','1234'
union all
select '2006/5/3','1111'
union all
select '2006/7/5','2222'
union all
select '2006/8/6','3333'
union all
select '2006/8/8','4444'
union all
select '2006/9/9','5555'


select fid=identity(int,1,1),fdate,fdata
into #t
from table1

select * from #t

子陌红尘 2006-09-06
  • 打赏
  • 举报
回复
如果每天只有不超过一条记录,可以用子查询方式实现,同样适用于Access:

select
(select count(*) from table1 where fdate<=t.fdate) as fid,
t.fdate,
t.fdata
from
table1 t
xiaoku 2006-09-06
  • 打赏
  • 举报
回复
临时表:你是不是想更改那表结构阿?


select fid=identity(int,1,1),fdate,fdata into #t from table1

直接查询 select * from #t
子陌红尘 2006-09-06
  • 打赏
  • 举报
回复
select identity(int,1,1) as fid,fdate,fdata into # from table1

select * from #

drop table #
lxzm1001 2006-09-06
  • 打赏
  • 举报
回复
alter table tablename add id int identity(1,1)
fuyu006 2006-09-06
  • 打赏
  • 举报
回复
select fid=identity(int,1,1) ,fdate,fdata from table1
九斤半 2006-09-06
  • 打赏
  • 举报
回复
晕,ACCESS的不懂
九斤半 2006-09-06
  • 打赏
  • 举报
回复
临时表

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧