Re: [SQL ] 资料结构不同的join问题

楼主: scpisces (失败的勇气。)   2014-08-26 20:07:08
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?
: 感谢!
作者: sleepwu ( )   2014-08-26 20:20:00
原来有pivot指令 明天来试试 感激不尽

Links booklink

Contact Us: admin [ a t ] ucptt.com