gpt4 book ai didi

mysql - 按特定条件订购商品,然后其余

转载 作者:行者123 更新时间:2023-11-29 03:52:03 25 4
gpt4 key购买 nike

我希望用户首先看到热门帖子,然后是按时间顺序排列的帖子的其余部分。

这是我的帖子表的样子:

+----+---------+----------+-------+
| id | title | trending | date |
+----+---------+----------+-------+
| 1 | title_1 | 0 | 1-nov |
| 2 | title_2 | 1 | 2-nov |
| 3 | title_3 | 1 | 3-nov |
| 4 | title_4 | 0 | 4-nov |
| 5 | title_5 | 1 | 5-nov |
+----+---------+----------+-------+

对于这个例子,用户应该看到 (5->3->2->4->1)

到目前为止,这是我的 sql 查询的样子:

SELECT *  FROM cards WHERE trending = 1 ORDER BY date DESC

最佳答案

您可以使用两列进行排序,您将根据 trending = 1 获得第一个结果,然后根据日期获得结果

SELECT *  FROM cards ORDER BY trending DESC, date DESC

关于mysql - 按特定条件订购商品,然后其余,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58727127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com