sql - 如何仅显示列 postgres 中的一个值
问题描述
我有一个具有三种状态的日期:打开、关闭、修复。但是,我试图仅显示 Open 状态值。我尝试使用 where 子句,但它不起作用。(注意:当使用 where 子句时,会有多个我不想显示的打开状态)。以下是我查询后的当前数据:
这是来自以下答案的查询
select distinct on("id")*,
status
from ticket
ORDER BY "id",CREATED DESC NULLS LAST
解决方案
我推测您想获得id
最新状态所在的票(s)open
- 并且只有那些票。如果是这样,distinct on
请在子查询中使用并随后过滤:
select t.*
from (select distinct on (id) t.*,
from ticket t
order by id, created desc nulls last
) t
where t.status = 'open'
推荐阅读
- python - 覆盖 get_context_data() 在子视图中不起作用
- spring - 是否可以将 Spring JpaRepository 和一些 CustomRepository 组合在一个可重用的接口中?
- c# - 寻找 RSS 的无限循环
- laravel - 如何在 Laravel 中为自定义验证规则创建自定义错误消息
- c# - 多个数据库之间的事务操作
- haskell - 打印教堂布尔值
- python - bash: ./run: 没有这样的文件或目录
- python - Selenium python web scraper 堵塞了我的 RAM:驱动程序和 xvfb 显示未在 display.stop() 和 driver.close() 之后关闭
- go - 我应该如何声明一个具有返回不同接口切片的方法的接口?
- python - 无论参数有多复杂,如何在 sort() 函数中指定关键参数?