矩阵的动态 SQL 查询 [英] Dynamic SQL Query for Matrix

查看:57
本文介绍了矩阵的动态 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来创建存储过程或动态 SQL 查询以查询矩阵并获得所需格式的输出.

I need some help in creating a stored procedure or a dynamic SQL query to query a matrix and have a output in a required format.

  • 数据库:SQL Server 2014
  • 状态表 - 屏幕截图:

所需的输出

更多州将添加到表格中.所以脚本应该能够动态获取所有的行和列.

More states will added to the table. So the Script should be able to dynamically get all the rows and columns.

输出是创建一个新表.

提前致谢.

推荐答案

试试下面的链接供您参考,它可能对您的逻辑有所帮助

Try this below links for your reference it may help you for logic

如何透视带有存储过程的 SQL Server 中的表?

动态SQL Server 中以动态日期作为列标题的透视查询

注意:上面的pivoting链接.最好参考它并做unipovt

Note: The above links for pivoting.better refer it and do the unipovt

这篇关于矩阵的动态 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆