--I've got a problem with this SUM and group by clause. I've tried to simplify all the table names for clarity and removed the joins but let me know if they are pivotal in solving this.
This bit below works ok, as expected:
SELECT M.WorkID, SUM(dbo.Pay.AMOUNT) AS Amount, dbo.Countries.towns
FROM
myTable...
bunch of inner Joins here...
GROUP BY M.WorkID, dbo.Countries.towns
HAVING (dbo.Countries.towns LIKE '%ville') AND (M.WorkID = '007')
WorkID - - Amount - - Towns
007 ---------- 12 --------- Smallville
007 ---------- 1004 ------ Nashville
However, I want to sum up all the *ville towns together, and so get '1014' in the result above for Amount.
I can't remove towns from the group by clause alone because its in the Select and Having clause and would error.
And if I remove towns from the entire query it looks like it adds up every column in the database table (even ones that don't have ID 007).
Anybody know what I need to do to sum up this Amount field and group certain towns together (and so it should give me the expected answer of 1014?)
TIA