I have problem with this 3 table below from MS ACCESS to do \"SQL CASE IF ELSE\" where I don\'t how to start.
Table A (Registrations)
Name | Desc
It's not too clear from the question how TableA
and TableB
are related togheter, but it looks like you want a UNION ALL
query and you want to exclude some categories:
SELECT
c.Name,
c.Year,
c.Class,
ab.Desc,
ab.Amount
FROM
TableC AS C INNER JOIN (
SELECT * FROM TableA WHERE Desc NOT IN ('BOOKS', 'UNIFORM', 'OTHERS')
UNION ALL
SELECT * FROM TableB WHERE Desc NOT IN ('BOOKS', 'UNIFORM', 'OTHERS')
) AS ab
ON c.Name = ab.Name AND c.Year = ab.Year
then you can use a Pivot using the previous query as a subquery:
TRANSFORM Sum(Amount) AS SumOfAmount
SELECT Name, Year, Class, Sum(Amount) AS [Sum_Amount]
FROM (
...the query above...
) AS s
GROUP BY Name, Year, Class
PIVOT Desc;