作者scpisces (失败的勇气。)
看板Database
标题Re: [SQL ] 资料结构不同的join问题
时间Tue Aug 26 20:07:08 2014
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?
: 感谢!
--
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.25.159.144
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Database/M.1409054831.A.2E6.html
1F:推 sleepwu: 原来有pivot指令 明天来试试 感激不尽 08/26 20:20