stat_dt::date - temp1.occur_date::date 装成presto
时间: 2024-02-04 15:02:16 浏览: 134
在Presto中,日期类型的计算和比较操作与Greenplum稍有不同。如果你想在Presto中执行类似的操作,可以使用 `DATE` 函数来进行日期类型的转换和计算。以下是将 `stat_dt` 和 `temp1.occur_date` 进行日期相减的示例:
```sql
DATE(stat_dt) - DATE(temp1.occur_date)
```
上述表达式将 `stat_dt` 和 `temp1.occur_date` 分别转换为日期类型,然后进行相减操作。请确保两个日期字段的格式正确,并且可以进行有效的日期计算。
相关问题
(stat_dt = date_format(last_day(to_date(stat_dt,'yyyyMMdd')),'yyyyMMdd') or stat_dt ='{DATE-1}')换成presto sql语法
在Presto SQL中,处理日期和时间的函数可能与你提供的语法有所不同,因为Presto SQL使用不同的函数来处理日期。下面是将你提供的SQL片段转换为Presto SQL语法的一个例子:
假设 `stat_dt` 是一个字符串格式的日期,你想得到上一个工作日或者当前日期的前一天(如果今天是工作日的话)。在Presto中,可以使用 `current_date` 获取当前日期,`date_add` 或者 `date_sub` 来进行日期的加减操作。为了处理工作日逻辑,可以使用 `dayofweek` 函数来确定当前是周几,并根据需要进行调整。
以下是转换后的Presto SQL代码示例:
```sql
WITH date_helper AS (
SELECT
CASE
WHEN dayofweek(current_date) = 1 THEN date_add('day', 2, current_date - INTERVAL '1' day) -- 如果今天是周日,则取前天
WHEN dayofweek(current_date) = 7 THEN date_add('day', 1, current_date) -- 如果今天是周六,则取明天
ELSE current_date - INTERVAL '1' day -- 其他情况取前一天
END AS prev_day,
current_date as today
)
SELECT
CASE
WHEN to_date(stat_dt) = last_day(to_date(stat_dt, 'yyyyMMdd')) THEN
date_format(last_day(to_date(stat_dt, 'yyyyMMdd')) - INTERVAL '1' day, 'yyyyMMdd')
WHEN stat_dt = date_format(current_date, 'yyyyMMdd') THEN
date_format(prev_day, 'yyyyMMdd')
ELSE stat_dt
END as adjusted_stat_dt
FROM your_table_name
```
请注意,这里使用了 `date_format` 函数来格式化日期,并且假设 `stat_dt` 是一个可以直接转换为日期的字符串。此外,`your_table_name` 需要被替换为你实际的表名。
在使用上述代码之前,请根据你的实际需求和数据情况进行相应的调整。
server: port: 8080 spring: datasource: username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8 druid: initial-size: 5 min-idle: 5 max-active: 20 max-wait: 60000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 100000 max-evictable-idle-time-millis: 300000 validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false pool-prepared-statements: true aop-patterns: com.example.demo.* stat-view-servlet: enabled: true login-username: root login-password: 123456 web-stat-filter: enabled: true url-pattern: /* exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' filters: stat,wall filter: stat: slow-sql-millis: 1000 log-slow-sql: true enabled: true wall: enabled: true config: drop-table-allow: false重写yml格式
我可以帮你重新格式化这段YAML格式的文本,如下所示:
```yaml
server:
port: 8080
spring:
datasource:
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
druid:
initial-size: 5
min-idle: 5
max-active: 20
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 100000
max-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
aop-patterns: com.example.demo.*
stat-view-servlet:
enabled: true
login-username: root
login-password: 123456
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
filters: stat,wall
filter:
stat:
slow-sql-millis: 1000
log-slow-sql: true
enabled: true
wall:
enabled: true
config:
drop-table-allow: false
```
希望这样的格式更易读和明了。如果你还有任何其他问题,请随时提问!
阅读全文
相关推荐

















