mysql - group by 和 order by,不工作 mysql
问题描述
我想订购一个帖子列表,id_post
并根据活跃或过时对其进行分组。status=1 when active
,status=2 when outdated
SELECT *,count(id_post) as count
FROM posts
WHERE 1
GROUP BY status
ORDER BY count DESC
我尝试使用这个 mysql 代码,但它只显示两个输出。我究竟做错了什么??
id_post title status
5 a 1
7 b 2
9 c 1
17 d 2
21 f 1
预期产出
21 f 1
9 c 1
5 a 1
17 d 2
7 b 2
解决方案
根据您的数据,您不需要使用GROUP BY
. 所以
select *
from posts
order by status ASC, id_post DESC
推荐阅读
- mobile - 带有附加/前缀下拉列表的文本表单
- optaplanner - 附近选择的条件概率分布 [Optaplanner]
- c# - 在 Visual Studio 的新解决方案中使用来自 github 的 Boostrap 模板
- c# - 是否存在 TaskPool 参考实现?
- elasticsearch - 为什么我的 Elasticsearch 查询检索所有索引文档
- c# - 如何在新记录水晶报表中显示上一条记录中某个公式的值
- loadrunner - 在 LOADRunner 中使用公式作为参数
- python - 如何在单个批处理请求中发送多个请求(批处理)
- python - Django PyTests - Visual Studio 代码 - 未发现测试,请检查测试的配置设置
- python - View 没有返回 HttpResponse 对象。它返回无