我有一个用户输入测试数据的需求--我有字段:
示例
Blood Pulse
---- -----
12 13还需要添加另一个字段,我们不知道测试的目的是什么。我在想要有一个名为Misc1Label,Misc1Value的字段
如果Misc1Label是口头的,Misc1Value是88岁
稍后,我可以使用Pivot,如果我们需要捕获Misc1Label的值,并使用Pivot,这样我就可以得到以下内容
Blood Pulse Oral
----- ---- ----
12 13 88我在想,是否还有其他最好的方法来处理这个问题。
提前感谢
发布于 2013-02-07 19:35:33
你真的需要把血和脉搏分开吗?你也可以把血液和脉搏看作是不同的属性。听起来像这样的东西可以工作,并且可以方便地查询,而不必使用枢轴命令。
PersonAttribute
PersonId int (I'm only presuming here)
AttributeId int
Attribute
AttributeId int
AttributeTypeId int
AttibuteValue varchar(100)
AttributeType
AttributeTypeId int
AttributeType varchar(100)然后,您可以将血液、脉搏、体重等存储在AttributeType表中,并将PersonAttribute表用作主表的1-N方法。这只是个想法。
SELECT Distinct PA.PersonId
FROM PersonAttribute PA
INNER JOIN Attribute A ON PA.AttributeId = A.AttributeId
INNER JOIN AttributeType AT ON A.AttributeTypeId = AT.AttributeTypeId
WHERE AT.AttributeType = 'Blood'当然,如果需要的话,同样的模式也可以被应用,将血液和脉搏留在你的主桌子上。
祝好运。
https://stackoverflow.com/questions/14759225
复制相似问题