sql - 仅当列在时间戳中时如何才能找到 DAYS 的差异?

标签 sql snowflake-cloud-data-platform

我有两列带时间戳。我试图在忽略小时和分钟的情况下找到仅 DAYS 的差异。
我在雪花中使用 SQL。

Ex :- I have both column values as following 
Column1 value = 07-DEC-16 11.05.24.500000000
Column2 value = 08-DEC-16 03.12.06.874000000
我只想减去 DAYS 的两列,在本例中,自 12 月 8 日至 12 月 7 日 =1

最佳答案

使用 DATEDIFF/TIMESTAMPDIFF :

Calculates the difference between two date, time, or timestamp expressions based on the date or time part requested. The function returns the result of subtracting the second argument from the third argument.

SELECT DATEDIFF(day, col1, col2)
FROM tab;
或者:
SELECT ABS(DATEDIFF(day, col1, col2)) -- absolute value
FROM tab;

关于sql - 仅当列在时间戳中时如何才能找到 DAYS 的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69573807/

相关文章:

python - Pandas 到 sql server

mysql - INNER JOIN 错误的 SUM 和 COUNT

sql - 基于 "type"列组合连续行

sql - 上个月获取日期

python - 使用 key 对身份验证的 Snowflake 的 SQLAlchemy engine.connect() 失败

sql - 如何处理同一列中多种日期格式的 Snowflake to_date 转换问题?

mysql - case 表达式来更改列的值

python - 雪花 Pandas pd_writer用NULL写入表

python - 当授予监控帐户权限时,有没有办法使用 python 查询计费使用情况?

snowflake-cloud-data-platform - 查询以获取雪花数据库中所有表的行数