J
J Welsby
I have a table with 3 fields - Name, Value, Month
After reading something about a Union query, I created the following select
query:
SELECT tblData.Name, Sum(tblData.Value) as Total
FROM tblData
GROUP BY tblData.Name
ORDER BY tblData.Name ASC
UNION ALL SELECT "Grand Total:", Sum(tblData.Value) as Total
FROM tblData;
What is interesting is that the last record becomes one with 'Grand Total'
appended in the Name column and the Total column showing the sum of all the
records:
Name Total
Jack 10
Sprat 30
Fat 30
Grand Total: 70
Question then, could this be expanded to a crosstab query so that a record
is added at the bottom of the query output which shows the total for each
column?
I tried this without success but was hoping that someone else had some idea
of how this could be accomplished. Following is the basic sql for a crosstab
query that works with this table:
TRANSFORM Sum(tblData.Value) AS SumOfValue
SELECT tblData.Name
FROM tblData
GROUP BY tblData.Name
PIVOT tblData.Month;
Anyone with much better sql skills than mine care to take a stab?
Many thanks in advance
After reading something about a Union query, I created the following select
query:
SELECT tblData.Name, Sum(tblData.Value) as Total
FROM tblData
GROUP BY tblData.Name
ORDER BY tblData.Name ASC
UNION ALL SELECT "Grand Total:", Sum(tblData.Value) as Total
FROM tblData;
What is interesting is that the last record becomes one with 'Grand Total'
appended in the Name column and the Total column showing the sum of all the
records:
Name Total
Jack 10
Sprat 30
Fat 30
Grand Total: 70
Question then, could this be expanded to a crosstab query so that a record
is added at the bottom of the query output which shows the total for each
column?
I tried this without success but was hoping that someone else had some idea
of how this could be accomplished. Following is the basic sql for a crosstab
query that works with this table:
TRANSFORM Sum(tblData.Value) AS SumOfValue
SELECT tblData.Name
FROM tblData
GROUP BY tblData.Name
PIVOT tblData.Month;
Anyone with much better sql skills than mine care to take a stab?
Many thanks in advance