Skip to content
Advertisement

Calculate SUM from one table and display columns from another

I have 2 tables, Employee, and Transaction

Transaction

tID cID carID eID tDate PickupDate ReturnDate Amount_Due

Employee

eID fName lName Job Manager Hired

I need to calculate the commission (2.5%) and display that along with fName and lName.

I’ve calculated the commission, I think I’ve done the join correctly but can’t quite figure out how to add in a SELECT to show the other two columns.

SELECT t.Amount_Due
    , SUM(t.Amount_Due*0.025) AS Commission
FROM [Transaction] t
JOIN Employee e ON t.eID = e.eID
GROUP BY t.Amount_Due

Advertisement

Answer

You are grouping by the wrong columns, and you are trying to select Amount_Due and aggregate it at the same time:

SELECT e.fName
    , e.lName,
    , SUM(t.Amount_Due * 0.025) AS Commission
    FROM [Transaction] t
    JOIN Employee e 
      ON t.eID = e.eID
    GROUP BY e.ID, e.fName, e.lName;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement