从sql中的结果集中删除一行

问题描述 投票:1回答:1

我正在尝试运行以下查询。因为我需要加入不同的表,其中包括所有表的结果。

假设查询是:

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得到结果。

sql postgresql join sql-delete
1个回答
0
投票

使用子查询,然后过滤掉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
© www.soinside.com 2019 - 2024. All rights reserved.