计算每个销售代表的佣金

时间:2016-11-30 03:32:48

标签: mysql sql sql-server database

有点卡在这个......

问题:计算每位销售代表的佣金,假设佣金是订单成本的5%。按员工姓氏和名字排序。

这个数据库.. http://richardtwatson.com/dm6e/images/general/ClassicModels.png

继承人我拥有的......

SELECT salesRepEmployeeNumber, amount * orderNumber AS commission, 
 CONCAT(firstName, ' ', lastName) AS sales_rep
  FROM Customers, Payments, Employees, Orders
    WHERE Payments.customerNumber= Customers.customerNumber
      AND (amount * orderNumber) * .05`

`

但显然不会在这个查询的位置!

TIA

2 个答案:

答案 0 :(得分:0)

好的,所以我想我可能已经弄清楚..如果有更简单的方法,请告诉我!

SELECT Customers.salesRepEmployeeNumber, CONCAT(firstName, ' ', lastName) AS Employee, (amount*5)/100 AS commission
FROM Customers, Payments, Employees
WHERE Payments.customerNumber= Customers.customerNumber
ORDER BY lastName, firstName;

答案 1 :(得分:0)

SELECT c.salesRepEmployeeNumber, CONCAT(firstName, ' ', lastName) AS Employee,(amount*0.05) AS commission
FROM Customers as c 
join Payments as p
     on c.customerNumber=p.customerNumber 
join Employees as e
     on p.customerNumber=e.customerNumber
ORDER BY lastName, firstName;