+ -
当前位置:首页 → 问答吧 → Access数据库查询问题

Access数据库查询问题

时间:2011-12-02

来源:互联网

请问Access怎么查询一张表的交替行数据呢?急。。。 

HonorCountry 表名

ID 是主键,数字

ID 里面的数字并不一定是连续的数字

sql怎么写呢??? 求助!

作者: dt891030   发布时间: 2011-12-02

ACCESS的?

作者: fredrickhu   发布时间: 2011-12-02

sql server 可以用row_numer(),Access怎么写
要不楼主就用程序实现吧

作者: pengxuan   发布时间: 2011-12-02

偶数行:
SQL code
create table tb(id int,dt varchar(10))
insert into tb select 1,'aa'
insert into tb select 2,'cc2'
insert into tb select 4,'fsa'
insert into tb select 7,'fe'
insert into tb select 12,'ewr'
insert into tb select 13,'tr'
insert into tb select 15,'ge'
insert into tb select 22,'he'
go
select id,dt from (select *,(select count(*) from tb where id<=a.id) as rn from tb a)t where rn%2=0 
--ACCESS 中:
select id,dt from (select *,(select count(*) from tb where id<=a.id) as rn from tb a)t where rn mod 2=0 
/*
id          dt
----------- ----------
2           cc2
7           fe
13          tr
22          he

(4 行受影响)

*/
go
drop table tb

作者: qianjin036a   发布时间: 2011-12-02

奇数行只要后面用 1 就行了.

作者: qianjin036a   发布时间: 2011-12-02

如果ID并不一定是对半的奇数和偶数呢

作者: dt891030   发布时间: 2011-12-02

因为要考虑的到被删除的ID,如果被删除的大多数是偶数

1.3.5.7.8.9.12.13.15

1.5.8.12.15
3.7.9.13



作者: dt891030   发布时间: 2011-12-02

引用 5 楼 dt891030 的回复:

如果ID并不一定是对半的奇数和偶数呢


这里是说的排列顺序上的奇数偶数,你不是要隔行取吗,你仔细看一看结果的ID.

作者: qianjin036a   发布时间: 2011-12-02