Hi, I'm looking to join columns from two tables A and S.
A: id (int) / d (datetime) / ant (int)
S: id (int) / d (datetime) / res (varchar) / el (int)
Table A holds the sales number for a certain department for a certain day.
Table S consists of complaints to a purchase where S.res is the problem and S.el being the number of tries before a complaint was answered. S.id and S.d equals that of table A.
Now I wanna join A and S to a table T that sums up each year for each department, with the following columns..:
T: id (int) the department / sales (int) total number of sales for the department / compl (int) total number of complaints / tries (int) total number of tries.
I already have the following SQL statement (SQL Server):
SELECT A.id AS dep, SUM(A.ant) AS sales, COUNT(S.res) AS compl, SUM(S.el) AS tries FROM A LEFT JOIN S ON A.id=S.id AND A.d=S.d WHERE YEAR(A.d)=2002 GROUP BY A.id;
The sales-column is counted more than one time if there are more than one complaint to the department a certain day. I have no idea how to combat this...
Hope I made the question understandable and that somebody has the solution!
Cheers!
A: id (int) / d (datetime) / ant (int)
S: id (int) / d (datetime) / res (varchar) / el (int)
Table A holds the sales number for a certain department for a certain day.
Table S consists of complaints to a purchase where S.res is the problem and S.el being the number of tries before a complaint was answered. S.id and S.d equals that of table A.
Now I wanna join A and S to a table T that sums up each year for each department, with the following columns..:
T: id (int) the department / sales (int) total number of sales for the department / compl (int) total number of complaints / tries (int) total number of tries.
I already have the following SQL statement (SQL Server):
SELECT A.id AS dep, SUM(A.ant) AS sales, COUNT(S.res) AS compl, SUM(S.el) AS tries FROM A LEFT JOIN S ON A.id=S.id AND A.d=S.d WHERE YEAR(A.d)=2002 GROUP BY A.id;
The sales-column is counted more than one time if there are more than one complaint to the department a certain day. I have no idea how to combat this...
Hope I made the question understandable and that somebody has the solution!
Cheers!