我一直在尝试编写一个Hive查询,它允许我选择具有至少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
现在我想在“西雅图”的同一天选择所有有“雨”的城市 结果就是,
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
感谢任何帮助。感谢
答案 0 :(得分:0)
如果您将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')
;