Employee表中有EmpName(员工),Tcxishu(提成系数),Commision(提成总计)字段
Bill表中有HandlePerson(员工),Sfqk(收费全款)字段,怎么写sql语句把 根据员工字段分类统计提成,提成是Tcxishu*Sfqk
3 个解决方案
#1
SELECT T1.EmpName,SUM(T1.Tcxishu*T2.Sfqk)[提成]
FROM Employee T1
LEFT JOIN Bill T2 ON T1.EmpName=T2.HandlePerson
GROUP BY T1.EmpName
#2
UPDATE Employee
SET Commision=(Bill.Sfqk)
from (select Bill.HandlePerson,SUM(Bill.Sfqk*Employee.Tcxishu) AS Sfqk from Bill INNER JOIN Employee ON Employee.EmpName = Bill.HandlePerson GROUP BY Bill.HandlePerson ) AS Bill
WHERE Employee.EmpName = Bill.HandlePerson
已经写好了,但是加上一个判断代码就报错,
#3
代码不要截图,重贴下吧,一个having改成了and
set 赋值语句有问题,
Bill表有RecordsT字段?
set 赋值语句有问题,
Bill表有RecordsT字段?
#1
SELECT T1.EmpName,SUM(T1.Tcxishu*T2.Sfqk)[提成]
FROM Employee T1
LEFT JOIN Bill T2 ON T1.EmpName=T2.HandlePerson
GROUP BY T1.EmpName
#2
UPDATE Employee
SET Commision=(Bill.Sfqk)
from (select Bill.HandlePerson,SUM(Bill.Sfqk*Employee.Tcxishu) AS Sfqk from Bill INNER JOIN Employee ON Employee.EmpName = Bill.HandlePerson GROUP BY Bill.HandlePerson ) AS Bill
WHERE Employee.EmpName = Bill.HandlePerson
已经写好了,但是加上一个判断代码就报错,
#3
代码不要截图,重贴下吧,一个having改成了and
set 赋值语句有问题,
Bill表有RecordsT字段?
set 赋值语句有问题,
Bill表有RecordsT字段?