Select 行至少有 1 个与特定行匹配的列值

Select rows having atleast 1 matching column value with a specific row

我一直在尝试编写一个 Hive 查询,它允许我 select 所有具有至少 1 个匹配特定列值的行与单个行,即


City     |   Mon  |  Tue  |  Wed  |  Thu  |  Fri  |  Sat  |  Sun
-----------------------------------------------------------------
Houston  |  Rain  |  Fog  |  Sun  |  Fog  |  Rain |  Sun  |  Sun
Denver   |  Sun   |  Sun  |  Sun  |  Sun  |  Fog  |  Sun  |  Sun
Seattle  |  Rain  |  Sun  |  Sun  |  Rain |  Rain |  Sun  |  Rain
Boston   |  Snow  |  Sun  |  Sun  |  Snow |  Snow |  Fog  |  Rain
Dallas   |  Sun   |  Sun  |  Sun  |  Sun  |  Sun  |  Rain |  Sun
StLouis  |  Rain  |  Sun  |  Fog  |  Rain |  Sun  |  Sun  |  Sun

现在我想 select 与 "Seattle" 在同一天有 "Rain" 的所有城市 所以结果是,

City     |   Mon  |  Tue  |  Wed  |  Thu  |  Fri  |  Sat  |  Sun
-----------------------------------------------------------------
Houston  |  Rain  |  Fog  |  Sun  |  Fog  |  Rain |  Sun  |  Sun
Seattle  |  Rain  |  Sun  |  Sun  |  Rain |  Rain |  Sun  |  Rain
Boston   |  Snow  |  Sun  |  Sun  |  Snow |  Snow |  Fog  |  Rain
StLouis  |  Rain  |  Sun  |  Fog  |  Rain |  Sun  |  Sun  |  Sun

感谢任何帮助。谢谢

如果将 Seattle 行连接到每一行,则可以逐列比较以确定是否应保留结果中的每一行:

SELECT
    t.*
FROM
    table t
INNER JOIN
    (SELECT * FROM table WHERE City = 'Seattle') s
WHERE
    (s.Mon = 'Rain' AND t.Mon = 'Rain') OR
    (s.Tue = 'Rain' AND t.Tue = 'Rain') OR
    (s.Wed = 'Rain' AND t.Wed = 'Rain') OR
    (s.Thu = 'Rain' AND t.Thu = 'Rain') OR
    (s.Fri = 'Rain' AND t.Fri = 'Rain') OR
    (s.Sat = 'Rain' AND t.Sat = 'Rain') OR
    (s.Sun = 'Rain' AND t.Sun = 'Rain')
;