我正在尝试排除所有总列均具有空白值的行。
样本数据:
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`
我找到了类似的东西,但在雪花中不起作用:
WHERE NOT ROW(gross_1, gross_2, gross_3) IS NULL
答案 0 :(得分:4)
使用coalesce()
:
select * from tablename
where coalesce(gross_1, gross_2, gross_3) is not null
答案 1 :(得分:2)
这取决于“空白”的含义。如数据所示:
select t.*
from t
where not (gross_1 = 'blank' and gross_2 = 'blank' and gross_3 = '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