简体   繁体   English

早餐列中的字符串位于午餐列中

[英]The string from the Breakfas column is in the Lunch column

I need to put in the result field the following value: true / false, depending on whether in the "Lunch" column there is a keyword that can be found in the "Breakfast" column.我需要在结果字段中输入以下值:真/假,这取决于“午餐”列中是否有可以在“早餐”列中找到的关键字。 The expected result is:预期结果是:

在此处输入图像描述

WITH Recipes AS
 (SELECT 'Blueberry pancakes' as Breakfast, 'Egg salad sandwich' as Lunch UNION ALL
  SELECT 'Potato pancakes', 'Toasted cheese sandwich' UNION ALL
  SELECT 'Ham scramble', 'Steak avocado salad' UNION ALL
  SELECT 'Tomato pasta', 'Tomato soup' UNION ALL
  SELECT 'Corned beef hash', 'Lentil potato soup')
SELECT *,

***Field for your code*** result,

FROM Recipes;

Unfortunately the function: contains_substr (Breakfast, 'Tomato pasta') only takes into account one given string, and not all of the strings in the whole "Lunch" column.不幸的是 function: contains_substr (Breakfast, 'Tomato Pasta') 只考虑一个给定的字符串,而不是整个“午餐”列中的所有字符串。

Does anyone know how to solve this?有谁知道如何解决这个问题?

Use below下面使用

select *,
  ( select count(*) > 0
    from unnest(split(Breakfast, ' ')) word1
    join unnest(split(Lunch, ' ')) word2
    on lower(trim(word1)) = lower(trim(word2))
  ) result
from Recipes              

if applied to sample data in your question - output is如果应用于您问题中的示例数据 - output 是

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM