【问题标题】:Querying multiple values, each with their own time span, in HIVE在 HIVE 中查询多个值,每个值都有自己的时间跨度
【发布时间】:2020-11-11 21:30:48
【问题描述】:

我想从适合可能值列表的表中选择所有设备。我可以这样使用 RLIKE:

select * from table where device_id RLIKE 'xx200|xx202|xx403|xx770|xx309|xx931|'

但我也想选择一个时间范围,每个device_id的时间范围不同

这如何在单个查询中完成?

如果我这样做:

select * from table WHERE timestamp >= '2010-09-01' AND timestamp <= '2013-08-31' AND where device_id RLIKE 'xx200|xx202|xx403|xx770|xx309|xx931|'

...显然这行不通,因为我只提供了一个时间戳范围。

【问题讨论】:

    标签: sql string datetime hive where-clause


    【解决方案1】:

    然后你将不得不打破正则表达式,并明确枚举范围/字符串条件对,如:

    SELECT *
    FROM mytable
    WHERE 
        (
            timestamp >= '2010-09-01' AND timestamp <= '2013-08-31' -- first range
            AND device_id LIKE '%xx200%'                            -- first string
        ) OR (
            timestamp >= '2010-10-01' AND timestamp <= '2013-09-31' -- second range
            AND device_id LIKE '%x403%'                             -- second string
        ) OR ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多