我有这些表,
rolls
并且rollsout
. 我想执行左外连接。
劳斯莱斯
|type|height|weight|Rate|
-------------------------
|RP |2ft | 200 | 100|
|RP |2ft | 200 | 100|
|RP |2ft | 200 | 100|
|LD |2ft | 100 | 130|
推出
|type|height|weight|Rate|
-------------------------
|RP |2ft | 200 | 100|
|RP |2ft | 200 | 100|
SUMing、JOINing 和 GROUPings 之后的预期输出 ==>
|type|height|SUM(rolls.weight)|SUM(rollsout.weight)|
----------------------------------------------------
|RP |2ft | 600 | 400 |
|LD |2ft | 100 | NILL |
我的代码:
SELECT rolls.hight,rolls.type,SUM(rolls.weight),SUM(rollsout.weight)
FROM rolls
LEFT OUTER JOIN rollsout
ON rolls.hight = rollsout.hight AND rolls.type= rollsout.type
GROUP BY rolls.hight,rolls.type
但上述代码的 O/P 是
|type|height|SUM(rolls.weight)|SUM(rollsout.weight)|
----------------------------------------------------
|RP |2ft | 1200 | 1200 |
|LD |2ft | 100 | NILL |
我不知道我哪里出错了——你能解释一下吗?