我正在尝试运行以下查询。出于某种原因,我需要加入不同的表,其中包括所有表的结果。
假设查询是:
Select a.value1, b.value2, c.value3
from a
join b on a.some_value = b.some_value1
join c on c.Some_other_value = b.some_diff_value
where (my conditions)...
假设上述查询的结果是:
value1 | value2 | value3
-------+--------+--------
1 | val1 | val2
1 | some1 | some2
2 | othr1 | othr2
3 | diff2 | diff3
我想从上面的结果集中删除 value1 不是 1 的值。
预期输出:
value1 | value2 | value3
-------+--------+--------
1 | val1 | val2
1 | some1 | some2
在 postgresql 中有什么方法可以实现这个目标吗?搜索了不同的主题,但在任何其他帖子中都没有线索。任何建议表示赞赏。
注意:我不能使用 where a.value1 = 1
因为 SQL 查询中的逻辑会导致丢失一些用于计算的记录。所以整个想法是按原样运行 SQL 查询,但在 Select 操作完成后删除记录,只得到 value1 = 1
的结果。
最佳答案
使用子查询然后过滤掉where子句中的a.value1=1
select * from
(
Select a.value1,b.value2,c.value3
from a join b on a.some_value=b.some_value1
join c on c.Some_othr_value=b.some_diff_value
where your conditions
)AA where a.value1=1
关于sql - 从sql中的结果集中删除一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55389041/