sql - PostgreSQL 全部
问题描述
我有以下表结构:
| id | object_id | status_id |
------------------------------
| 1 | 12 | 1 |
| 2 | 12 | 2 |
| 3 | 18 | 5 |
我需要选择所有object_id
处于状态 1 和 2 的状态。也就是说,像这样:select object_id from table_name where status_id in (1, 2)
,但我需要status_id
不在列出的值之一中,而在两者中。也就是说,从上表中,我应该返回值 12(因为object_id
statuses 等于 12)。如何才能做到这一点?
解决方案
如果您只需要状态 1 或 2 中的唯一对象 ID,则可以使用distinct
关键字。:
select distinct object_id from table_name where status_id in (1, 2)
推荐阅读
- c# - 在异步函数中使用 statehaschanged() 和 while 循环时在 blazor 应用程序中滞后
- php - PHP访问json对象中的数组
- hive - java.lang.ArrayIndexOutOfBoundsException: -1 - Hive 更新语句
- python - 我可以在哪里报告 Python 中的错误?或者有人可以告诉我发生了什么事?
- javascript - 克隆一个数组并使其独一无二 - Javascript
- node.js - 带有 Lambda HTTP GET 请求 (Node.js) 502 错误网关的 AWS API 网关
- node.js - aws lambda 函数中的待处理承诺
- solr - Nutch solr 指数失败
- sql - SQLServer 2016 - BCP 在使用临时表时生成空文件
- python-3.x - 无法点击链接
- 元素列表python代码