枢轴排入列Firebird 2.1
我有一张桌子,里面有几公里大约100公里 公里表
我需要将行旋转成这样的列。 枢轴行列为列
- 列的列数固定在行中= 10公里,
- 可以重复并具有10公里差距,示例:263、263、264、265、270 ..
我认为使用“递归”,但网上几乎没有例子( 如果您能帮助我解决问题,我将非常感激!
I have a table containing several kilometers about 100
table of kilometers
I need to rotate rows into columns like this
pivot rows into columns
- The number of columns is fixed in rows = 10
- Kilometers can be repeated and have gaps, for exemple: 263, 263, 264, 265, 270..
I think to use "with recursive", but there are few examples on the net (
I would be very grateful if you could help me solve the problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在评论中提到的那样,这可能是您的演示层中更好的解决方案,而不是通过查询来解决。我不确定是否可以使用(递归)CTE解决此问题,但是我可以使用
Execute Block
在PSQL中为您提供解决方案(这也可以以存储过程的形式完成) 。该解决方案将行映射到列,并在填充所有列后启动新行。
在Firebird 4.0中,您可以通过窗口功能获得相同的结果。
对于firebird 3.0,替换
min(km)过滤器(column_group = n)
用min(decode(column_group,n,km))
>或column_group = n然后km)
(其中n为0,1,..,9)。As I mentioned in the comments, this is probably something better solved in your presentation layer, instead of through a query. I'm not sure if this can be solved with a (recursive) CTE, but I can offer you a solution in PSQL using
EXECUTE BLOCK
(this can also be done in the form of a stored procedure).This solution maps rows to columns, and starts a new row when all columns have been filled.
In Firebird 4.0 you can achieve the same result with window functions.
For Firebird 3.0, replace
min(km) filter (where column_group = n)
withmin(decode(column_group, n, km))
ormin(case when column_group = n then km)
(where n is 0, 1, .., 9).