presto sql 获取中秋节所在年月日和日期
时间: 2024-03-12 14:50:25 浏览: 125
您好,您可以使用Presto SQL中的日期函数来获取中秋节所在年月日和日期,具体查询语句如下:
```
SELECT
date_extract('year', date_add('day', CASE
WHEN day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) - 1 <= 0
THEN day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) + 6
ELSE day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) - 1
END + (15 - 1) * 7, date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp)))),
date_extract('month', date_add('day', CASE
WHEN day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) - 1 <= 0
THEN day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) + 6
ELSE day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) - 1
END + (15 - 1) * 7, date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp)))),
date_add('day', CASE
WHEN day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) - 1 <= 0
THEN day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) + 6
ELSE day_of_week(date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp))) - 1
END + (15 - 1) * 7, date_trunc('year', cast(date_parse('2021-09-21', '%Y-%m-%d') as timestamp'))) AS 中秋节日期
```
其中,'2021-09-21'为任意一个中秋节所在年份的某一个日期,可以根据实际情况进行修改。查询结果中,第一列为中秋节所在年份,第二列为中秋节所在月份,第三列为中秋节日期。
阅读全文