根据列名计算值

问题描述:

我有三张表,我需要计算一些因素。这些表的格式为:根据列名计算值

t1: id | height | weight  | .. 
    1 |  180 | 190  | .. 

t2: id | adjustmentFactor 
    1 | 0.05 

t3: attribute | multOrDivide 
    height |  1 
    weight |  0 

我需要产生对形式的这些表的视图:

id | adjustedHeight | adjustedWeight... 
1 |  9   |  3800 

其中

adjustedAttribute = 
attribute * adjustmentFactor, if multOrDivide = 1 for that attribute, 
attribute/adjustmentFactor, if multOrDivide = 0 for that attribute 

有什么办法适用这两个调整形式取决于attributeName在SQL查询中?

+0

可以显示一些样本数据和预期的输出吗? –

+0

您在t1有多少个其他列?将t1表达为“id |属性|值”会更有意义。 – gsun

+0

t1中有数百个列。我同意将这些属性设置为行会更有帮助,但是表已经处于透视形式,并且我无法真正更改该模式。 – user1742188

不,不可能将列名称用作逻辑语句的一部分。您的应用程序需要构建一个专门插入这些值的SQL语句。