select A,B,C,number1,[TF],[TT],[FF]
from
(
select a.A,a.B,a.C,a.D+a.E as F,a.number2,b.number1
from table2 as a
left join table1 as b on a.A=b.A and a.B=b.B and a.C=b.C
) as a
pivot
(
sum(number2) for F in ([TF],[TT],[FF])
) as pvt
※ 引述《sleepwu ( )》之铭言:
: 数据库名称:SQL server 2008
: 内容/问题描述:
: 因为不太好描述,我将table简化,请直接点连结看图。
: 我有两张table如http://tinyurl.com/pconsga
: 其中ABC栏都是string,A and B and C是key值,D E栏用来判断number2的属性。
: 我拿table2 right join table 2 on 1.A=2.A and 1.B=2.B and 1.C=2.C
: 结果因为key值重复,会显示为table3,但我想要呈现为table4的样子。
: http://tinyurl.com/k4lssjz
: 请问这种资料结构该怎么join或是怎么group?
: 感谢!