SELECT t.EmployeeID, isnull(sum(t1.value),0) as c1,
isnull(sum(t2.value),0) as c2FROM EMPLOYEE t left join Table1 t1 on t1.EmployeeID=t.EmployeeID
and t1.type=10 and t1.flag=1
left join Table1 t2 on t2.EmployeeID=t.EmployeeID
and t2.type=11 and t1.flag=1Where t.cid=110
group by t.EmployeeID
order by t.EmployeeID结果
employeeid c1 c2
1 10 555
2 12 777
3 10 888C1列的值正常
问题是C2列的更本没那么大 我看了下也不是C1+C2的值
isnull(sum(t2.value),0) as c2FROM EMPLOYEE t left join Table1 t1 on t1.EmployeeID=t.EmployeeID
and t1.type=10 and t1.flag=1
left join Table1 t2 on t2.EmployeeID=t.EmployeeID
and t2.type=11 and t1.flag=1Where t.cid=110
group by t.EmployeeID
order by t.EmployeeID结果
employeeid c1 c2
1 10 555
2 12 777
3 10 888C1列的值正常
问题是C2列的更本没那么大 我看了下也不是C1+C2的值
应该和表结构什么没关系SELECT t.EmployeeID,isnull(sum(t2.value),0) as c2 FROM EMPLOYEE t
left join Table1 t2 on t2.EmployeeID=t.EmployeeID
and t2.type=11 and t2.flag=1 Where t.cid=110
group by t.EmployeeID
order by t.EmployeeID 结果
employeeid c2
1 100
2 111
3 123
原来是
employeeid c1 c2
1 10 20
2 12 40
3 10 60如果去掉T1表的left join
employeeid c2
1 10
2 20
3 30数值翻了一个倍 但还是不知道是为什么