问一个sql的问题,我不会!

打转的风铃 2010-02-02 10:26:46
我想查前六条吧,就写select top 6 .

那我要是查7---12条的记录,怎么写啊?
13---18啥的!谢谢!!!
...全文
246 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
打转的风铃 2010-02-02
  • 打赏
  • 举报
回复
没有ID的话,是不是只有用not in!!!
heronexus 2010-02-02
  • 打赏
  • 举报
回复
给你思路:想TOP 12一下,倒序输出,在TOP 6一下输出,得到的记录就是7~12条的记录了!
kele1006 2010-02-02
  • 打赏
  • 举报
回复

select * from (select row_number() over (order by Id) as rowId ,* from tb) t
where t.RowId between 7 and 12
奔腾286 2010-02-02
  • 打赏
  • 举报
回复
select top 12 * from table where not in (select top 7 * from table)
qxq421367660 2010-02-02
  • 打赏
  • 举报
回复
写错了应该是:select * from tb_name where id>7 and id<12
qxq421367660 2010-02-02
  • 打赏
  • 举报
回复
select * from tb_name where 12>id or id>7
这种方法也行
打转的风铃 2010-02-02
  • 打赏
  • 举报
回复
up^_^
xiongshao1943 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 fengjian_428 的回复:]
select top 12* from tb where id not in(select top 7 id from tb )
[/Quote]
正解了,就是换一种思路
ouc_ajax 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 ulihss 的回复:]
SQL codeselecttop6*from cn_H_ContactUswhere idnotin(selecttop7 idfrom cn_H_ContactUs )
应该这样做。
[/Quote]

up! 如果是Oracle的可以看看Row_num关键字。
Kobayashi 2010-02-02
  • 打赏
  • 举报
回复
select top 6 * from cn_H_ContactUs where id not in(select top 7 id from cn_H_ContactUs  )

应该这样做。
kan1232008 2010-02-02
  • 打赏
  • 举报
回复
with t_rowtable as(select row_number() over(order by z.ID) as row_number,z.ID from table as z) select * from t_rowtable where row_number>='" + start + "' and row_number < ='" + end + "' order by ID


只能用在SQL2005
cngothic 2010-02-02
  • 打赏
  • 举报
回复
你这样要做什么分页?

select top 6 max(id), * from table
记录num = max(id)

select top 6 max(id), * from table where id > num
记录num = max(id)

select top 6 max(id), * from table where id > num
记录num = max(id)
HooverHuang 2010-02-02
  • 打赏
  • 举报
回复
select top 12* from cn_H_ContactUs where id not in(select top 7 id from cn_H_ContactUs )
HooverHuang 2010-02-02
  • 打赏
  • 举报
回复
你换个思路想象撒。。。

你要查 7-12条的,
你排序下,然后将 前6条 排除,再去前5条不就可以了么

查出前 6条的ID,然后条件里面写 ,id不等于这6 个ID的前 5五条数据就是你想要的
fengjian_428 2010-02-02
  • 打赏
  • 举报
回复
select top 12* from tb where id not in(select top 7 id from tb )
zishanyan 2010-02-02
  • 打赏
  • 举报
回复
如果只是Sql语句的话,我就做下搬运工发个链接上来

http://bbs.tech.ccidnet.com/read.php?tid=111362
打转的风铃 2010-02-02
  • 打赏
  • 举报
回复
1
diegoyu 2010-02-02
  • 打赏
  • 举报
回复
select top 6* from Employee where ID not in(select top 6 ID from Employee)
小昭 2010-02-02
  • 打赏
  • 举报
回复
7-12,就是5条,你可以select top 5 * from table where id not in (select top 7 id from table)
加载更多回复(10)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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