根据多列排除行

Exclude row based on multiple columns

我试图排除所有毛列都为空值的行。

示例数据:

market   item_id    gross_1     gross_2   gross_3   period
POLAND   1111       1           2         3         20190301
ESTONIA  2222       blank       2         3         20190302
POLAND   3333       1           blank     3         20190303
POLAND   3333       1           blank     blank     20190304
POLAND   4444       blank       blank     blank     20190305
POLAND   5555       1           2         3         20190306`

我想收到:

market   item_id    gross_1     gross_2   gross_3   period
POLAND   1111       1           2         3         20190301
ESTONIA  2222       blank       2         3         20190302
POLAND   3333       1           blank     3         20190303
POLAND   3333       1           blank     blank     20190304
POLAND   5555       1           2         3         20190306`

我找到了类似的东西,但它在 snowflake 中不起作用:

WHERE NOT ROW(gross_1, gross_2, gross_3) IS NULL

这取决于 "blank" 的含义。如数据所示:

select t.*
from t
where not (gross_1 = 'blank' and gross_2 = 'blank' and gross_3  = 'blank')

如果"blank"表示空串,则:

select t.*
from t
where not (gross_1 = '' and gross_2 = '' and gross_3 = '')

如果表示NULL,则:

select t.*
from t
where not (gross_1 is null and gross_2 is null and gross_3 is null)

所有这些都可以改写为or:

select t.*
from t
where gross_1 is not null or gross_2 is not null or gross_3 is not null

使用coalesce():

select * from tablename
where coalesce(gross_1, gross_2, gross_3) is not null