需要帮助将数据从表转换为报告中的特定格式
有人可以提供建议
这是原始数据
Source Table data
Year ID Value
1YR Low 0.048
1YR High 0.13
1YR Val 0.09
3YR Low 0.058
3YR High 0.096
3YR Val 0.077
Output
Val Range
1 Yr 0.09 0.048 to 0.13
3 Yr 0.077 0.058 to 0.09
答案 0 :(得分:0)
可能需要稍微整理,但这是我认为你需要的:
SELECT val.year, val.value, cast(low.value as varchar(6))
+ ' to ' + cast(high.value as varchar(6)) as range
from yourTable val
INNER JOIN yourTable low on val.year = low.year
INNER JOIN yourTable high ON
val.year = high.year
where val.id='val'
AND low.id='Low'
AND high.id='High'