我正在尝试在 BigQuery (标准 SQL)中编写一个非常标准的 date_trunc 查询,但它没有运行

发布于 2025-01-18 19:45:58 字数 482 浏览 1 评论 0原文

我只在Postgres仓库(RedShift)上使用过SQL,所以我没有意识到BigQuery到目前为止使用了不同的版本...下面是我试图运行的查询:

SELECT date_trunc ('month', c.created) AS month
     , COUNT (DISTINCT (c.id)) AS charges
FROM stripe.charges c
GROUP BY 1
ORDER BY 1

然后这是我收到的错误消息:

java.sql.sqlexception:[simba] [bigqueryjdbcdriver](100032)错误执行查询作业。消息:需要有效的日期零件名称,但发现C.在[1:29]

上创建。

我在BigQuery Date_trunc上阅读了大约15个不同的堆栈溢出件,但是所有这些都比我的问题更复杂...结果,我尝试过的任何事情都没有工作...

I have only ever used SQL on a postgres warehouse (Redshift), so I didn't realize that BigQuery used a different version until now... Below is the query that I'm trying to get to run:

SELECT date_trunc ('month', c.created) AS month
     , COUNT (DISTINCT (c.id)) AS charges
FROM stripe.charges c
GROUP BY 1
ORDER BY 1

And then here is the error message I receive:

java.sql.SQLException: [Simba][BigQueryJDBCDriver](100032) Error executing query job. Message: A valid date part name is required but found c.created at [1:29]

I've read about 15 different stack overflow pieces on bigquery date_trunc, but all of them are for more complex problems than mine... As a result, nothing I've tried has worked...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稳稳的幸福 2025-01-25 19:45:58

您必须切换date_trunc参数的顺序,然后从'月份'中删除引号:

SELECT date_trunc (c.created, month) AS month
     , COUNT (DISTINCT (c.id)) AS charges
FROM stripe.charges c
GROUP BY 1
ORDER BY 1

You have to switch the order of the parameters of DATE_TRUNC and remove the quotes from 'month':

SELECT date_trunc (c.created, month) AS month
     , COUNT (DISTINCT (c.id)) AS charges
FROM stripe.charges c
GROUP BY 1
ORDER BY 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文