如何忽略单元格中的某个值并移至下一行

how to ignore a certain value in a cell and move on to next row

我有一个有四行的 table。

column1 | column2 | column3
---------------------------
 a      | role    | N/A
 b      | N/A     | N/A
 c      | N/A     | year
 c      | year    | N/A

有没有一种方法可以在 select 语句中得到像

这样的结果
column1 | column2 | column3
---------------------------
 a      | role    | can be N/A or null
 c      | year    | year

忽略 N/A。 谢谢

您可以使用聚合:

select column1, max(nullif(column2, 'N/A')) as column2,
       max(nullif(column3, 'N/A')) as column3
from t
group by column1;

我意识到这是假设第二行中的 column1 值确实是 "a" 而不是 "b"。

戈登的查询需要额外的过滤器:

select *
from (
    select 
        column1, 
        max(nullif(column2, 'N/A')) as column2,
        max(nullif(column3, 'N/A')) as column3
    from a_table
    group by 1
    ) s
where column2 notnull or column3 notnull
order by 1;

 column1 | column2 | column3
---------+---------+---------
 a       | role    |
 c       | year    | year
(2 rows)