當前位置:首頁 » 操作系統 » 資料庫查詢倒序

資料庫查詢倒序

發布時間: 2023-05-03 16:21:09

① 怎麼讓網頁讀取資料庫後倒序顯示

按id號從小到大排列
sql = "select * from tablename order by id asc"
按id號從大到小排列
sql = "select * from tablename order by id desc"

舉例如下:
下面是一段正常的源碼,它可以正常查詢出倒序結果:
<!--#include file="conn.asp" -->

<head>

<title> 回眸一笑</title>

<style><!--@import url(in/index.css);--></style>
<style><!--@import url(in/layer.css);body,td,th {
font-family: 宋體;
color: #000;
}
--></style>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>

<body text="#000000" >

<div id="newest">
<div id="ntitle" align="right">最新10篇帖子:</div>
<div id="space"></div>
<div id="nmarquee">
<table width="100%" height="12" border="0" cellpadding="0" cellspacing="0">
<tr>
<td id=demo1>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<%
Dim nSql
nSql="Select top 10 * From [Dv_Topic] Order By TopicID DESC"

Dim nRs
Set nRs=Server.CreateObject("ADODB.RecordSet")
nRs.Open nSql,Conn1,1,1
while not nRs.eof
%>
<td height="17"><table width="500"><tr><td width="492" height="10">

<a href='../../xiabbs/Dvbbs8.2.0_Ac/dispbbs.asp?TopicIDid=<%=nRs("TopicID")%>'>
<strong><font color="#333366"><%=left(nRs("PostUserName"),5)%></font></strong>
<font color="#FF3366"> 發貼於 </font>
<strong><font color="#333366"><%=left(nRs("DateAndTime"),12)%></font></strong>:<%=left(nRs("Title"),20)%>
</a></td></tr></table></td>
<%
nRs.movenext
wend
nRs.close:set nRs = nothing
%>
但是把它的鏈接更改,使它指向其它ID,但查詢結果卻順序顯示了。代碼如下:
<!--#include file="conn.asp" -->

<head>

<title>回眸一笑</title>

<style><!--@import url(in/index.css);--></style>
<style><!--@import url(in/layer.css);body,td,th {
font-family: 宋體;
color: #000;
}
--></style>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>

<body text="#000000" >

<div id="newest">
<div id="ntitle" align="right">最新10篇帖子:</div>
<div id="space"></div>
<div id="nmarquee">
<table width="100%" height="12" border="0" cellpadding="0" cellspacing="0">
<tr>
<td id=demo1>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<%
Dim nSql
nSql="Select top 10 * From [Dv_Topic] Order By TopicID DESC"
nSql="Select top 10 * From [Dv_Topic] Order By boardid DESC"<!--這里添加了查詢表,以為下面鏈接提供ID鏈接-->

Dim nRs
Set nRs=Server.CreateObject("ADODB.RecordSet")
nRs.Open nSql,Conn1,1,1
while not nRs.eof
%>
<td height="17"><table width="500"><tr><td width="492" height="10">
<!--下面的鏈接添加了boardid以便動態鏈接。-->
<a href='../../xiabbs/Dvbbs8.2.0_Ac/dispbbs.asp?boardid=<%=nRs("boardid")%>&id=<%=nRs("TopicID")%>'>
<strong><font color="#333366"><%=left(nRs("PostUserName"),5)%></font></strong>
<font color="#FF3366"> 發貼於 </font>
<strong><font color="#333366"><%=left(nRs("DateAndTime"),12)%></font></strong>:<%=left(nRs("Title"),20)%>
</a></td></tr></table></td>
<%
nRs.movenext
wend
nRs.close:set nRs = nothing
%>

② 怎樣倒序獲取sql資料庫中的數據

你要是記不住哪個是倒序,哪個是順序,只要記住由小到大還有由大到小

DESC 很明顯比 ASC 長,也就是說DESC 是由大到小
ASC 短,就是由小到大;默認為ASC

select top 1 * from tables order by column_id desc 取的是最大的ID列的行;

③ 資料庫怎麼查詢按金額捐款多少倒序顯示

order by 列名 asc/desc;其中asc是指定列按升序排列,desc則是指定列按降序排列。
例如:select 捐款金額 from 表 order by 捐款金額 desc;

④ sql的倒序排列命令怎麼輸入

Select * From 表名 Where ID In (Select Max From 表名 Group By 過濾重復的項名) 。

SQL語言,是結構化查詢語言(StructuredQueryLanguage)的簡稱。SQL語言是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統;同時也是資料庫腳本文件的擴展名。

SQL語言是高級的非過程化編程語言,允許用戶在高層數據結構上工作。它不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同資料庫系統可以使用相同的結構化查詢語言作為數據輸入與管理的介面。SQL語言語句可以嵌套,這使他具有極大的靈活性和強大的功能。

⑤ 如何修改使得資料庫查詢結果倒序顯示

select * from table order by id desc

最後一個關鍵字:desc,就是使用倒序排列的意思。

熱點內容
29乘法手指速演算法 發布:2025-09-14 16:11:30 瀏覽:828
iosandroidhtml5 發布:2025-09-14 16:10:39 瀏覽:923
systemuiapk反編譯 發布:2025-09-14 15:46:44 瀏覽:991
php本地安裝 發布:2025-09-14 15:44:59 瀏覽:343
壓力大緩解壓力聽什麼歌 發布:2025-09-14 15:39:35 瀏覽:305
Java中文代碼 發布:2025-09-14 15:39:33 瀏覽:659
java除 發布:2025-09-14 15:38:59 瀏覽:577
python爬蟲存儲資料庫 發布:2025-09-14 15:29:03 瀏覽:947
解壓球捏不動 發布:2025-09-14 15:26:52 瀏覽:799
1的存儲形式 發布:2025-09-14 15:01:19 瀏覽:349