我是oracle 11g的新手。我做了一些研究,但没有一个完全符合我的要求..
这是我的表格。
T1
Date_ Name Subject Mark
2011 AAA History 80
2011 AAA CS 85
2013 AAA Math 90
2013 AAA Science 91
2013 AAA CS 92
T2。这是一个比例表
Subject Weight
Math 2
CS 2.1
History 1.9
Science 2
我希望我的输出为:
T3
Date_ Name Math History CS Science
2011 AAA 160 178.5
2013 AAA 180 193.2 182
非常感谢!
答案 0 :(得分:0)
您正尝试使用乘法因子进行转轴。以下是使用显式聚合处理此问题的方法:
select Date_, Name,
sum(case when Subject = 'Math' then T1.Mark * T2.Weight end) as Math,
sum(case when Subject = 'History' then T1.Mark * T2.Weight end) as History,
sum(case when Subject = 'CS' then T1.Mark * T2.Weight end) as CS,
sum(case when Subject = 'Science' then T1.Mark * T2.Weight end) as Science
from T1 join
T2
on T1.Subjecct = T2.Subject
group by Date_, Name;