[英]Get data when date is equal to or greater than 90 days ago
I wonder if anyone here can help with a BigQuery piece I am working on.我想知道这里是否有人可以为我正在研究的 BigQuery 提供帮助。 I'm trying to pull the date, email and last interaction time from a dataset when the last interaction time is equal to or greater than 90 days ago.
当最后一次交互时间等于或大于 90 天前时,我正在尝试从数据集中提取日期 email 和最后一次交互时间。
I have the following query:我有以下查询:
SELECT
date,
user_email,
DATE_FROM_UNIX_DATE(gmail.last_interaction_time) AS Last_Interaction_Date,
DATE_ADD(CURRENT_DATE(), INTERVAL -90 DAY) AS Days_ago
FROM
`bqadminreporting.adminlogtracking.usage`
WHERE
'Last_Interaction_Date' >= 'Days_ago'
However, I run into the following error:但是,我遇到以下错误:
DATE value is out of allowed range: from 0001-01-01 to 9999-12-31
DATE 值超出允许范围:从 0001-01-01 到 9999-12-31
As far as I can see, it makes sense - so not entirely sure why its throwing out an error?据我所知,这是有道理的——所以不完全确定它为什么会抛出错误?
Looks like you have some inconsistent values (data) in filed gmail.last_interaction_time
, which you need to handle to avoid error.看起来您在提交的
gmail.last_interaction_time
中有一些不一致的值(数据),您需要对其进行处理以避免错误。
Moreover above query will not work as per your expected WHERE conditions, you should use following query to get expected output.此外,上述查询不会按照您预期的 WHERE 条件工作,您应该使用以下查询来获得预期的 output。
SELECT * FROM
(SELECT
date,
user_email,
DATE_FROM_UNIX_DATE(gmail.last_interaction_time) AS Last_Interaction_Date,
DATE_ADD(CURRENT_DATE(), INTERVAL -90 DAY) AS Days_ago
FROM
`bqadminreporting.adminlogtracking.usage`)
WHERE
Last_Interaction_Date >= Days_ago
Presumably, your problem is DATE_FROM_UNIX_DATE()
.据推测,您的问题是
DATE_FROM_UNIX_DATE()
。 Without sample data, it is not really possible to determine what the issue is.如果没有样本数据,实际上不可能确定问题所在。
However, you don't need to convert to a date to do this.但是,您无需转换为日期即可执行此操作。 You can do all the work in the Unix seconds space:
您可以在 Unix 秒空间中完成所有工作:
select u.*
from `bqadminreporting.adminlogtracking.usage` u
where gmail.last_interaction_time >= unix_seconds(timestamp(current_date)) - 90 * 60 * 60 * 24
Note that I suspect that the issue is that last_interaction_time
is really measured in milliseconds or microseconds or some other unit.请注意,我怀疑问题在于
last_interaction_time
实际上以毫秒或微秒或其他单位为单位。 This will prevent your error, but it might not do what you want.这将防止你的错误,但它可能不会做你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.