簡體   English   中英

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

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

我需要在結果字段中輸入以下值:真/假,這取決於“午餐”列中是否有可以在“早餐”列中找到的關鍵字。 預期結果是:

在此處輸入圖像描述

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;

不幸的是 function: contains_substr (Breakfast, 'Tomato Pasta') 只考慮一個給定的字符串,而不是整個“午餐”列中的所有字符串。

有誰知道如何解決這個問題?

下面使用

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

如果應用於您問題中的示例數據 - output 是

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM