简体   繁体   English

Excel透视表存储在SQL 2008中/交叉表

[英]Excel pivot table Storing in SQL 2008 / Cross tabbed tables

Let's say I have a table with X and Y values like: 假设我有一个包含XY值的表,例如:

      x-1  x-2   x-3 
 y-1  V=1  v=4   v=6       
 y-2  V=1  v=4   v=67
 y-3  V=2  v=0   v=9
 y-4  V=4  v=5   v=62

where the value for x-1 , y-1 is 1 and so on. 其中x-1y-1值为1 ,依此类推。

I need to store all the x value field names, all the y value field names, and all values. 我需要存储所有x值字段名称,所有y值字段名称以及所有值。

You could do something as simple as: 您可以做一些简单的事情:

+-------------------+
|    RowName        |
+-------------------+
| +uid int          |
| name nvarchar(50) |
| position int      |
+-------------------+

+-------------------+
|    ColumnName     |
+-------------------+
| +uid int          |
| name nvarchar(50) |
| position int      |
+-------------------+

+-------------------+
|      Value        |
+-------------------+
| +row int          |
| +column int       |
| value  int        |
+-------------------+

Note that the '+' above denotes a primary key (so, row and column together in the Value table would make up the primary key). 请注意,上面的“ +”表示主键(因此,值表中的行和列一起将构成主键)。

This would enable you to quickly dump the row and column names into their respective tables (while also maintaining the position where the name should appear when recreating the layout) and would provide a quick way to store your data based upon the tabular layout. 这将使您能够快速将行名和列名转储到它们各自的表中(同时还保留了重新创建布局时名称应出现的位置),并提供了一种基于表格布局的快速存储数据的方法。

This approach doesn't really have any inherent "failsafes," other than ensuring that you can't accidentally duplicate a row/column pair, but it's a quick and dirty way to store what you're trying to represent. 除了确保您不会意外地复制行/列对之外,该方法实际上没有任何固有的“故障保护”,但这是一种快速而肮脏的方式来存储您要表示的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM