问题描述
query
------
apple
no fruit
this is
not a number
query count
------ ------------
apple 1
no fruit 2
this is 2
not a number 3
解决方法
一种方法是拆分为数组并计算元素:
select t.*,size(split(query,' '))
如果要将多个空格作为单个定界符进行计数:
select t.*,'[ ]+'))
,
您需要拆分列内容,例如
select *,'[\\s]+')) as count
from table_a
使用空格\s
速记字符不仅可以忽略多个空格,还可以忽略制表符等。