SQL資料庫表中查詢第三到倒數第六條記錄

時間 2022-02-07 04:55:02

1樓:匿名使用者

你的表裡有沒有主健?.還有就是有沒有設定預設排序?你所說的最後一條紀錄有沒有條件?

如果以上都不算.sql如下:

select top 1 id from 表 order by id desc

2樓:匿名使用者

--table是你的表的名字

--id是你的表的主鍵

select * from tablewhere id not in

(select top 3 id

from table

)and id not in

(select top 6 id

from table order by id desc)

3樓:匿名使用者

select * from 表 whereid not in (select top 6 muserid from 表 order by id desc)

and id not in (select top 3 muserid from 表 order by id)

當然id得是有順序的。

4樓:jg_陳

declare @cnt int;

set @cnt=(selct count(*) from tablename);

select * from (select *,row_number() over(order by col desc) as row from tablename) as a

where a.row>=3 and a.row<=@cnt-6

5樓:匿名使用者

select * from tablename where id>=3 and id<=6

如何從sql資料庫表中查詢倒數第三到倒數第六條記錄

6樓:

在排序的時候用desc就是倒序排列.

倒數第一就是第一條記錄.

rs.absolute(int) 比如我要從第三條開始顯示則用rs.absolute(2)

然後rs.next()就是第三條了.顯示倒第六條的時候break就可以了.

7樓:

use 資料庫名

godeclare @totle int

select @totle=count(*) from 表名select top (@totle-2) * from 表名except

select top (@totle-6) * from 表名go以上**在sql server 2005上成功返回從倒數第三到倒數第六的4條記錄.

8樓:匿名使用者

select top 4 * from

(select top 6 * from tablename where ... order by fieldname desc) tmp

order by fieldname asc

sql語句中 我想查詢從第三條開始到第六條怎麼寫

9樓:

使用rownum標誌行的序號,但要記住rownum的生成是在order by之前

你要查第三條到第六條必然是有一個順序的, 假設這個順序是 rowid (物理儲存地址)

select * from

(select rownum rn , a.* -- 這裡使用rownum給每行新增一個偽列(行號)

from (select * from tab a order by rowid) a -- 這裡是將原資料按想要的順序排列好

)where rn >= 3 and rn <= 6

10樓:近火樓臺

樓上的都是 oracle 的吧? sqlserver 裡沒有這些方法呼叫,可以這樣子:

select top 3 * from (select top 5 * from a order by id) aa order by id desc

樓主可以根據自己的情況加排序或條件

11樓:匿名使用者

select top 5 * from news where id not in (select top 2 id from news where mokuai='榮川新聞') and mokuai='榮川新聞'

12樓:

select * from (select column1,column2...,rownum as a from tab) where a>=3 and a<=6

13樓:匿名使用者

select * from tble limit 4,3

怎麼按條件選取資料庫表中的倒數5-10位

14樓:匿名使用者

首先不存在倒數和正數的概念,因為:假設升序(asc)是正數的話,那麼降序(desc)就是倒數,這一點可以用**控制。

好了,解決倒數的問題,剩下的就是5-10位的問題,很簡單,rownum大於5小於等於10就可以了。

對於你的例子,假如降序是正數的話:

select * from dianshiju where sname='張三' and dsjid not in(select top 5dsjid from dianshiju where name='張三') and rownum>5 and rownum<=10 order by id

15樓:衡修

什麼倒數5-10位?不明白,top 5 查詢出來,最多也就是5條資料。

sql語句中 我想查詢從第三條開始到第六條怎麼寫

16樓:

如果有id欄位:

select * from 表 where id>=3 and id<=6

如果沒有

select top(6) from 表

把recordset用迴圈或者兩遍語句 movenext兩次迴圈4次得到3~6條記錄

17樓:匿名使用者

select top 5 * from news where id not in (select top 2 id from news where mokuai='榮川新聞') and mokuai='榮川新聞'

18樓:噹噹

select * from 表 where rownum between 3 and 6

19樓:匿名使用者

select * from 表 where id>=3 and id<=6

如果 id不是數字行的就麻煩了,要看是哪個順序為準了。

sql如何把查到的前六條資料倒序排列?

20樓:匿名使用者

如下是一個倒序分頁,通過改變6和0的值來實現你想要的效果其中6和0的關係是(頁數-1)*頁面大小select top 6 * from 表 where 條件 and 編號 not in (select top 0 編號 from 表 where 條件 order by 編號 desc) order by 編號 desc

21樓:匿名使用者

select top 6 欄位名 from 表名 where 條件 order by 要排序欄位名 desc order by 排序,如果不加desc或者使用acs 則是正序,desc是倒序

22樓:匿名使用者

select xx from xx where rownum<7 desc

sql查詢 如何獲取查詢某id的一條記錄在表中是第幾條記錄

23樓:匿名使用者

可以用row_number函式,如以下資料:

id    name

1       張三

3       李四

5       王五

7       趙六

如查詢王五這條資料在資料庫裡是回第幾條,可以這樣答。

select t.rn from

(select *,row_number() over(order by id) rn from 表名) t

where t.name='王五'

結果會顯示為3,也就是第三條資料

24樓:沉默使用者

查詢一下小於等於id值的記錄數就行了

select count(*) from 表 where id<=id的值

25樓:匿名使用者

沒學過access.不過可以指點個思路..就是給這張表中增加一列nid,查某id的時候順便查出nid..

26樓:

如果是oracle

select rownum

from

where .id=

sql資料庫中所有表中查詢關鍵字

說一下你的資料庫還有 關鍵字 唄 那就要用到索引了,具體怎麼寫語句 我忘了 你可以看下書 這個語句應該不難。該 關鍵字 是表名中?欄位名中?還是表中的記錄中?如何查詢出一個資料庫中所有表名包含某個關鍵詞的表名的列表 sql資料庫裡有很多表,但是不知道關鍵字在哪個表裡,怎麼查?資料庫中有很多的表,表裡...

SQL資料庫,如何把一張表從資料庫中插入到另外資料庫?如何寫語句

如果兩個表結構完全一樣的,用insert into data2.table2 select from data1.table1 如果結構不一樣或者你要指定欄位,用insert into data2.table2 欄位1,欄位2,欄位 select 欄位j,欄位k,欄位m from data1.tab...

sql中如何把資料庫中幾個表的資料匯入到另資料庫中的表

insert into ddd 欄位1,欄位2,欄位3 select 欄位1,欄位2,欄位3 from aaa,bbb,ccc 插入的欄位和查詢的欄位數量型別一致 由於你的誇庫查詢插入 所以在表名前加 庫名.使用者名稱 insert into b.使用者.ddd 欄位1,欄位2,欄位3 select...