gpt4 book ai didi

tsql - Reporting Services - 如果当前为 NULL,则获取前一列值

转载 作者:行者123 更新时间:2023-12-02 03:18:05 25 4
gpt4 key购买 nike

我正在尝试减少 T-SQL 查询返回到 Reporting Services 的数据的大小。例如,假设我们有以下行集:

ID  Country City
1 Germany Berlin
2 Germany Berlin
3 Germany Berlin
4 Germany Berlin
5 Germany Hamburg
6 Germany Hamburg
7 Germany Hamburg
8 Germany Hamburg
9 Germany Berlin
10 Germany Berlin

它可以很容易地转换成这样:

ID  Country City
1 Germany Berlin
2 NULL NULL
3 NULL NULL
4 NULL NULL
5 NULL Hamburg
6 NULL NULL
7 NULL NULL
8 NULL NULL
9 NULL Berlin
10 NULL NULL

因为我可能有成千上万的重复值(和数百列),所以我知道像这样使用 NULL 转换数据会显着减少返回数据的大小。

是否有可能实现一个公式,如果当前列为 NULL,则获取前一行列的值?

我想测试是只渲染大量数据还是处理较小的数据但应用这样的表达式会更快。

最佳答案

为什么不直接使用Group BY

SELECT Min(Id) as min, Max(ID) as max,Country,City 
FROM myTable
GROUP BY Country,City

或者

SELECT count(Id) as rowRepeatNum,Country,City 
FROM myTable
GROUP BY Country,City

如果您的 ID 是连续的,第一种方法会起作用,尽管我不确定 ID 是否重要。

第二种方法可以为您提供一个向下循环的数字,以相当快地在您的应用程序中生成重复行并返回明显更少的行。

能否提供有关您的用例的更多信息?

关于tsql - Reporting Services - 如果当前为 NULL,则获取前一列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35359308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com