當前位置:首頁 » 編程語言 » sql排序置頂
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql排序置頂

發布時間: 2022-06-19 15:40:19

① 請教sql 置頂排序語句

使用Where關鍵字

1

Select id From table1 Where topFlag=1 order by topFlag desc, updateDate desc

② sql 把特定數據排在最前面

在該表加一個參考的排序欄位就可以了,或者用:
select name from table where name='D'
union all
select name from table where name<>'D'

③ 請問有沒有辦法用一條sql語句來實現置頂功能

在文章表裡有top布爾型欄位 我原來的sql語句是sql="select * from 表名 order by 時間 desc where top=true" 來顯示置頂文章,然後再用sql="select * from 表名 order by 時間 desc where top=false" 來顯示不是置頂的文章,可是這樣做的話,雖然可以實現置頂的功能,但是這樣那些置頂的文章在每一頁都會出現,並且也不便於分頁的製作,使每一頁都一樣條數的新聞沒法控制,因為置頂的新聞可能沒有也可以是多條。。
你的意思是order by後面加2個條件吧.
order by top asc, 時間 desc
其實不如分成兩個。這樣性能更好

④ sql 置頂排序

試驗了一下下面這個可以:
oracle:
select t.id,t.tname,t.tdate from teacher t left join consume c on t.id=c.tid order by c.id,tdate desc;
select t.id,t.tname,t.tdate from teacher t left join consume c on t.id=c.tid order by nvl(c.id,9999999),tdate desc;

sqlserver:
select t.id,t.tname,t.tdate from teacher t left join consume c on t.id=c.tid order by isnull(c.id,9999999),tdate desc;
*****************************************************
補充:
access:
SELECT t.id, t.tname, t.tdate
FROM teacher AS t LEFT JOIN consume AS c ON t.id=c.tid
ORDER BY iif(isnull(c.id),999999,c.id), tdate DESC;
*****************************************************
---
以上,希望對你有所幫助。

⑤ sql語句(mysql),如何實現百度貼吧,新增回復帖子置頂的排序方式

建議你在tb_topic:中增加一個欄位lastreply_time,你可以根據這個來排序,插入回復的時候確實需要增加一個更新語句,但查詢時很方便,只要按照這個欄位的時間排序就行了

⑥ 求SQL語句:怎麼才能根據置頂,置頂到期時間和更新時間進行排序

使用Where關鍵字

=1orderbytopFlagdesc,updateDatedesc

⑦ sql過期置頂排序

select * from table where date<getdate() order by is_pro asc,date desc union all select * from table where date>getdate() order by is_pro desc,date asc

desc asc 你自己調試下,我看暈了。應該這樣寫 沒有問題。

⑧ 帖子置頂,SQL語句,資料庫表的設計

一個嵌套查詢就可以了啊
比如置頂為1,非置頂為0
select
*
from
(select
*
from
bbs
order
by
ctime
desc)
c
order
by
istop
desc
1.先查詢出按時間倒序結果集
2.在上一個結果集中查詢按置頂倒序的結果集