sql - 我可以应用“NULLS LAST”之类的东西,但不按非空的列值排序吗?
问题描述
想象一下我有疑问
SELECT "somethings.*
FROM "somethings"
ORDER BY description DESC NULLS LAST, popularity DESC`
它将首先对描述进行排序,将所有带有null
描述的行放在最后,然后应用流行度排序。
但我想要的只是将具有空描述的行放在最后,而不是对描述字符串的主要结果进行排序,然后根据受欢迎程度对结果进行排序。
理想情况下,我想在一个查询中实现它。
解决方案
您可以使用is null
inorder by
子句:
order by (case when description is null
then 1 else 0 end), description desc, popularity desc;
推荐阅读
- python - 如何在python中修改字典
- javascript - 为什么我的角度拦截器从本地存储中获取令牌的旧值?
- azure - Office365:使用“AADSTS9002313”invalid_grant execption 刷新访问令牌结果
- javascript - Node Express 渲染 Dom 元素
- python - 如何将自定义用户模型添加到管理面板的用户部分 - django 3.1.1
- azure-devops-rest-api - 如何通过 AzureDevOps REST API 仅获取最新版本的包
- python - 是否可以从 url 编码帖子数据中停止 Python 请求库?
- excel - 使用列表框调用用户窗体时出现运行时错误
- coq - 从向量转换的列表等于从转换其类型的向量转换的列表
- nlp - OpenAI API 和 GPT-3,不清楚如何访问或设置学习/开发?