Google SQL Pivot make 0 显示 NULL

发布于 2024-09-08 17:43:34 字数 1173 浏览 2 评论 0原文

我有一个数据透视表,只要数据库中没有值,我就需要返回 NULL。当您查看 Google API 的查询语言时,这似乎非常简单: http://code.google.com/apis/visualization/documentation/ querylanguage.html#Pivot

Google 显示空值的示例
(来源:cjweed.com

我的图表没有空值
(来源:descentcampaign.com

Google 示例为第一个图像。注意它如何包含 null,这些 null 值来自原始表中不存在的数据。当我运行 sum(vals) 以使枢轴工作时,它总是返回 0,即使它不存在。

另外,我的sql语句是:
<代码> SELECT weekNumber, sum(value) FROM allval
其中 weekNumber != 0 AND custId != 28
按周数分组
PIVOT custId
按周数排序

注意 custId != 28。它仍然出现在我的结果表中,只是所有内容都设置为 0。

任何人都知道链接中的 Google 示例如何能够通过聚合函数 sum 来维护 NULL 值?

I have a pivot table that I need to have return NULL whenever there is not a value in the database. This seems pretty simple when you look at the Google API for their query language:
http://code.google.com/apis/visualization/documentation/querylanguage.html#Pivot

Google's Example showing nulls
(source: cjweed.com)

My chart does not have nulls
(source: descentcampaign.com)

The Google example is the first image. Notice how it contains null, these null values are from data that does not exist in the original table. When I run the sum(vals) for the pivot to work, it always returns 0, even if it doesn't exist.

Also, my sql statement is:

SELECT weekNumber, sum(value) FROM allval
WHERE weekNumber != 0 AND custId != 28
GROUP BY weekNumber
PIVOT custId
ORDER BY weekNumber

Notice the custId != 28. It still appears in my result table, except everything is set to 0.

Anyone know how the Google example in the link was able to maintain the NULL values even through the aggregate function sum?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文