SELECT Table1.Item,
CASE (Table2.Type)
WHEN 'Variable' THEN SUM(Table1.Cost)
END AS V_Cost,
CASE (Table2.Type)
WHEN 'Fixed' THEN SUM(Table1.Cost)
END AS F_Cost
FROM Table1 INNER JOIN
Table2 ON
Table1.TYPE = Table2.Type
GROUP BY Table1.Item,
Table2.Type
The SUM function should be outside the CASE function rather than inside.
SELECT Table1.Item,
SUM(CASE Table2.Type
WHEN 'Variable'
THEN Table1.Cost
ELSE 0 END) AS V_Cost,
SUM(CASE Table2.Type
WHEN 'Fixed'
THEN Table1.Cost
ELSE 0 END) AS F_Cost
FROM Table1 INNER JOIN
Table2 ON
Table1.TYPE = Table2.Type
GROUP BY Table1.Item Terry L. Broadbent - DBA
Computing Links:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.