过滤掉雪花中的空字符串

时间:2020-07-01 18:26:38

标签: sql filtering snowflake-cloud-data-platform blank-line

我有一个非常简单的任务,事实证明这是不可能的。我有一列包含字符串,但在应该作为一个单词的地方也有空格(这些不是NULL,它们只是空字符串)。例如:

LastName1,
EmptyRow,
LastName2,
EmptyRow,
EmptyRow,
LastName3...

由于空行不为NULL,所以IS NOT NULL函数不起作用。

最终,我只需要过滤掉其中实际包含值的所有行,并消除所有空行。有人可以提出建议吗?

3 个答案:

答案 0 :(得分:1)

如果混合使用单个空格,没有空格和null,则使用类似的内容

其中Coalesce(trim(lastname),'')<>''

答案 1 :(得分:1)

您可以通过对其应用LENGTH函数来过滤掉这些记录。

WHERE LENGTH(TRIM(COL_NAME)) > 0

答案 2 :(得分:0)

您需要知道“空”行的含义。最有可能是空字符串:

Best = ['England','India','New Zealand','South Africa']
Good = ['Australia','Pakistan','Sri Lanka','West Indies']
Average = ['Afghanistan','Zimbabwe','Netherlands','Ireland']
Satisfactory = ['Kenya', 'Bermuda','Canada','Scotland']

for B in Best:
    for i in range(len(df['Opposition'])):
        if df['Opposition'].iloc[i]== B:
            df['Opposition'].iloc[i] = "Best"
for G in Good:
    for i in range(len(df['Opposition'])):
        if df['Opposition'].iloc[i]== G:
            df['Opposition'].iloc[i] = "Good"
for A in Average:
    for i in range(len(df['Opposition'])):
        if df['Opposition'].iloc[i]== A:
            df['Opposition'].iloc[i] = "Average"
for S in Satisfactory:
    for i in range(len(df['Opposition'])):
        if df['Opposition'].iloc[i]== S:
            df['Opposition'].iloc[i] = "Satisfactory"

如果您需要确保至少有一个字母可以使用:

where lastname > ''

或:

where lastname regexp '[a-zA-Z]'