一个关于mysql置顶查询的问题

一个关于mysql置顶查询的问题,第1张

用union all吧,伪代码如下:

(select * from wenzhang where type='置顶')union all select * from (select * from wenzhang where type!='置顶' order by time) as tmp

表结构news: id titlecontenttimeauthordescriptionflag

flag作为标记,如果取其中三条数据,则把对应的三条数据的flag设置为1(推荐),默认为0;这样就可以实现取其中的三条数据,剩下的为按时间排序;

取三条:select * from news where flag = 1 limit 3

取剩余的数据select * from news where flag = 0 order by time desc limit 10


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7366244.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存