sql - 搜索过滤列
问题描述
使用 Postgres,我需要在一个有 9 列的表上进行搜索,我只需要其中的 4 个,第一、第二、第六和第七。
我需要的是只有这四列的搜索结果,其中第 6 列和第 7 列不同,在结果中保持第 1、第 2、第 6 和第 7 列的顺序这是第 6 和第 7 列是子项和奖金的示例
我对此很陌生,如果你能告诉我如何得到这个结果,我真的很感激。
psql=> select employee_id, registration, children, bonus from rewards_plan;
employee_id | registration | children | bonus
--------------------+--------+----------+--------------
65000 | 180047 | 1 | 1
76000 | 154177 | 1 | 0
97000 | 223181 | 2 | 1
16000 | 195381 | 1 | 0
25000 | 301554 | 1 | 1
解决方案
WHERE 子句不限于 SELECT 列表中的列。
您可以使用:
select employee_id, registration, children, bonus
from rewards_plan
where sixth_column <> seventh_column;
如果这两列可以包含 NULL 值,您可能需要使用“null-safe”比较:
select employee_id, registration, children, bonus
from rewards_plan
where sixth_column is distinct from seventh_column;
推荐阅读
- ios - 如何在 Xcode 中指定框架的配置?
- xml - 如何在 VBA 中重命名 .xml 文件
- mysql - 错误类型错误:无法读取tipo-struttura.component.ts (angular+spring+sql) 处未定义的属性“id”
- python - Lightgbm 在同一个数据集上进行不同的分割(一种热编码与一对一分割算法)
- python - IfcOpenShell 从 IfcWall 中查找坐标
- python-3.x - 如何访问 chat_id 并将其保存以供进一步执行?
- powerbi - 将唯一匹配项计数为计算列
- node.js - 使用节点js检查mongo db中的条件字段datetime是否大于或等于currentdatetime
- python - OPC UA 僵尸连接
- c# - Serilog 解构子类