SQL Reporting Services - 我可以对包含表达式的字段求和吗?

发布于 2025-01-07 21:14:52 字数 100 浏览 1 评论 0原文

如果我的 SQL 2008 报告中有一个通过表达式(意味着不是直接从数据集生成)生成的字段,我应该能够对其进行求和吗?我可以以某种方式在后续表达式中引用该字段 - 例如通过引用框名称吗?

If I have a field in my SQL 2008 report that is generated via expression (meaning not directly from a dataset) should I be able to SUM it? Can I reference the field in a subsequent expression somehow - like by referencing the box name?

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

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

发布评论

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

评论(1

丑疤怪 2025-01-14 21:14:52

你的问题并不完全清楚......但我会尝试一下。

您的意思是这样吗:

SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_That_Has_Infinite_Rows
WHERE rowId BETWEEN 3 AND 8

这将计算 6 个数字的总和(因为 BETWEEN 语句的范围包含两端)。
您将无法在 WHERE 子句中“立即”引用字段别名 -

SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_With_One_Row
WHERE randomSum > 5  -- throws error, field 'does not exist'

但是,它将在 ORDER BYGROUP BY 中可用code> 子句,以及如果您将查询包装在其他内容中(CTE、内联表、etx);

SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_With_Thousand_Rows
GROUP BY randomSum  -- although this won't have any apparent effect here

Your question isn't completely clear... but I'll take a stab at it.

Do you mean something like this:

SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_That_Has_Infinite_Rows
WHERE rowId BETWEEN 3 AND 8

This will sum 6 numbers (because the range of a BETWEEN statement is inclusive on both ends).
You won't be able to reference the field alias 'immediately' in the WHERE clause -

SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_With_One_Row
WHERE randomSum > 5  -- throws error, field 'does not exist'

However, it will be available in ORDER BY and GROUP BY clauses, and also if you wrap the query in something else (CTE, inline table, etx);

SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_With_Thousand_Rows
GROUP BY randomSum  -- although this won't have any apparent effect here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文