sum,cross the column and row?

  • Thread starter Thread starter spark
  • Start date Start date
S

spark

Guest
I need create a query based on a table:TBL1 like this:
jan feb mar
company1 1 1 1
company2 2 2 2
company3 3 3 3
company4 4 4 4
company5 5 5 5
company6 6 6 6
company7 7 7 7
My targtes result is as the following:
jan feb mar Qtr1
company1 1 1 1 3
company2 2 2 2 6
company3 3 3 3 9
company4 4 4 4 12
company5 5 5 5 15
company6 6 6 6 18
company7 7 7 7 21
Total: 28 28 28 84
I am quite new about access query.Please help. Any suggestion will be appreciated.
Thanks.
Spark
 
First I suspect that your db design is wrong, but anyways:

If your table is structured only (!) the way you showed in example then you need to
1. create a query of your tbl1 with SQL like this, call it query2

SELECT "Total:" AS Total, Sum(tbl1.Jan) AS Jan, Sum(tbl1.Feb) AS Feb, Sum(tbl1.Mar) AS Mar, [Jan]+[Feb]+[Mar] AS Quarter1
FROM tbl1
GROUP BY "Total:";

2. create another query with SQL like this

SELECT tbl1.Comp, tbl1.Jan, tbl1.Feb, tbl1.Mar, [Jan]+[Feb]+[Mar] AS Quarter1
FROM tbl1
UNION select *
from query2;
 

Users who are viewing this thread

Back
Top Bottom