① 请教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.在上一个结果集中查询按置顶倒序的结果集