Access数据库查询问题

dt891030 2011-12-02 02:39:17
请问Access怎么查询一张表的交替行数据呢?急。。。

HonorCountry 表名

ID 是主键,数字

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

sql怎么写呢??? 求助!
...全文
45 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
dt891030 2011-12-02
  • 打赏
  • 举报
回复
感谢 qianjin036a

结贴了
-晴天 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dt891030 的回复:]

(select *,(select count(*) from tb where id<=a.id) as rn from tb a)t

怎么理解()t?
[/Quote]

别名.
dt891030 2011-12-02
  • 打赏
  • 举报
回复
问题已经解决了 谢谢qianjin036a
dt891030 2011-12-02
  • 打赏
  • 举报
回复
(select *,(select count(*) from tb where id<=a.id) as rn from tb a)t

怎么理解()t?
-晴天 2011-12-02
  • 打赏
  • 举报
回复
1
2
4
7
12
13
15
22
取出
2
7
13
22
-晴天 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 dt891030 的回复:]

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

这里是说的排列顺序上的奇数偶数,你不是要隔行取吗,你仔细看一看结果的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
  • 打赏
  • 举报
回复
如果ID并不一定是对半的奇数和偶数呢
-晴天 2011-12-02
  • 打赏
  • 举报
回复
奇数行只要后面用 1 就行了.
-晴天 2011-12-02
  • 打赏
  • 举报
回复
偶数行:
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
pengxuan 2011-12-02
  • 打赏
  • 举报
回复
sql server 可以用row_numer(),Access怎么写
要不楼主就用程序实现吧
--小F-- 2011-12-02
  • 打赏
  • 举报
回复
ACCESS的?

34,589

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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