sql - 寻找一些 SQL 帮助我有一个我想从中提取的列并且无法为其创建选择任何建议都会有所帮助
问题描述
有人可以帮我弄清楚如何编写一个选择语句来抓取像这样的列中@符号之后的单词任何帮助将不胜感激我在looker中使用sql runner @附加到我无法做到的单词上在帖子中
所以我永远不会知道需要拉多少个单词可能是 1 或 50,并且可能希望该列看起来像 revjahwar、nhl 等...我建立了这个联合但仍然可能有大量 @ 的 id 有拉出来,所以它不是太有效
@revjahwar #51&Done #21reasons #21dayswithPrime #IminmyPurpose #Purpose=Peace #iBelieve #Tiredofplayinggames #2019AintNobodyCare @ NFL
到目前为止,如果您关注评论,则有一种方法可以拉出迄今为止的第一个评论
解决方案
Snowflake 的REGEXP_SUBSTR()
函数“返回与字符串中的正则表达式匹配的子字符串”,这似乎是您在这里想要做的。这是一个例子。
with INSTAGRAM_POST_METRICS as (select $1 caption from values('@ revjahwar #51&Done #21reasons #21dayswithPrime #IminmyPurpose #Purpose=Peace #iBelieve #Tiredofplayinggames #2019AintNobodyCare @ NFL'))
select regexp_substr(
caption,
'@ ([^ ]+)',
1,
1,
'e'
) word from INSTAGRAM_POST_METRICS;
word
revjahwar
这是获取所有@words的方法
with INSTAGRAM_POST_METRICS as (select $1 caption from values('@ revjahwar #51&Done #21reasons #21dayswithPrime #IminmyPurpose #Purpose=Peace #iBelieve #Tiredofplayinggames #2019AintNobodyCare @ NFL'))
SELECT array_to_string(array_agg(word), ',') word_list
FROM (
SELECT caption,
split_part(t.value, ' ', 2) word
FROM instagram_post_metrics,
lateral flatten(split(caption, '@')) t
WHERE t.value != '')
GROUP BY caption;
推荐阅读
- php - PHP表单被提交但数据为空
- python - OpenAPI 生成的架构请求正文显示默认值而不是类型
- vb.net - 发布问题 VB.Net “目标 GatherAllFilesToPublish 不存在?”
- jakarta-ee - 如何控制一次执行一个无状态会话bean的方法?
- docker - Docker-compose 双美元符号:我可以从内部引用环境变量吗?
- android - 从图库中选择图像时的图像选择限制
- r - R:带有冒号运算符和空向量长度的 For 循环
- xcode - JSON::ParserError - 416: '"#define RSAPrivateKey_dup GRPC_SHADOW_' 处出现意外标记
- python - 为什么在pygame中使用翻转功能后图像会留下像素?
- angular - jhipster 和主细节