HiveQL在特定日期范围内选择生日

时间:2018-09-27 12:08:50

标签: sql hive hiveql

我有下表persons

id name   location dob
1  John   NY       1978-08-02
2  Nancy  LA       1993-10-12
3  Smith  GA       1986-09-25
4  Emily  MN       1988-04-14
5  Lily   MN       1978-11-02

如何编写HiveQL来选择当前日期和2个月之间的生日:

例如

select current_date
>> 2018-09-27

select add_months(current_date,-2);
>> 2018-07-27

在这些日期之间选择birthdays

id name   location dob
1  John   NY       1978-08-02
3  Smith  GA       1986-09-25

1 个答案:

答案 0 :(得分:1)

生日问题很棘手:

**this is a  problem of **CRON** please set as header like   this**`
access-control-allow-headers: Origin, Content-Type, Accept
access-control-allow-origin: *
cache-control: public, max-age=7200
cf-cache-status: MISS
cf-ray: 3f460ec8f96e8ca6-VIE
content-encoding: br
content-type: application/javascript; charset=UTF-8
date: Wed, 28 Feb 2018 20:15:46 GMT
etag: W/"2b9-1616e050fe8"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expires: Wed, 28 Feb 2018 22:15:46 GMT
last-modified: Wed, 07 Feb 2018 02:08:01 GMT
server: cloudflare
strict-transport-security: max-age=2592000
vary: Accept-Encoding
via: 1.1 vegur`enter code here`
x-content-type-options: nosniff
X-Firefox-Spdy: h2
x-powered-by: Express` 

基本上,您只需要对月份和日期进行比较,而不必对年份进行比较。然后,您必须考虑期间超过一年的边界。