S
S Davis
Hello,
I have a single table with the following fields:
CLASS
CATEGORY
READDIFF
CODE
DATE
Before I go to far, I should explain one thing: CLASS, CATEGORY, and
CODE are hierarchically related; CODE being between 1 - 10000 and the
lowest child, CATEGORY being the parent of code and having 3
variations, and CLASS being the parent of CATEGORY and having 6
variations. Eventually I would like to display 18 lines of data (6
CLASS with 3 CATEGORY each), with the CODES being grouped together
under each CLASS and CATEGORY and used as unique identifiers to sum
READDIFF on each line. Example:
Note: this data also includes the field DATE, not shown here, which is
explained further below)
CLASS CATEGORY CODE READDIFF
1 1 1 10
1 1 2 15
1 1 3 20
1 2 4 10
1 2 5 7.5
1 2 6 5
1 3 7 10
1 3 8 5
1 3 9 2
2 1 10 10
2 1 11 50
....
6 1 18 75
would be displayed as:
CLASS CATEGORY SumOfREADDIFF
1 1 17
1 2 22.5
1 3 17
2 1 70
....
6 1 75
The above is what I'm trying to achieve.
I need to find some way, either in one query or in a thousand
subqueries, to return what I had outlined above. However, the
additional field of DATE will also need to be used to set boundaries
for summing READDIFF. Ie., sum all READDIFF between 1/1/1900 and
1/1/1901, but exclude anything before or after.
Additionally, there are many instances of the same CODE, as each CODE
has had multiple readings put into the database at different times.
Trying to group together CODE (which seems the simple solution) gives
me problems because each CODE has a unique time and date and also a
different READDIFF. Example:
CODE READDIFF DATE
1 10 1/1/1900
1 5 1/1/1901
1 2 1/1/1902
So trying to do a simple GroupBy on the CODE and a Sum of READDIFF
still results in three unique lines due to the DATE, except where of
course there are two or more DATE that are the same. Unfortunately,
DATE must be included so that the timelines can be established. This
seems to be a flaw (as far as with what I want ot have happen in
access) that constricts me to having to perform a GROUP BY on DATE
since I am performing a SUM on READDIFF and a GROUP BY on CODE. I do
not want to group DATE together, but merely use it as a filter.
Using the simply GROUP BY and SUM functions, I end up with a result
that is approximately 25,000 lines long, rather than the 18 I am
seeking.
Best I can explain in text is to show:
Each unique MRC
Each unique CATEGORY under each MRC
Group together all CODE which are the same
Sum all READDIFF for each grouped CODE as CODEDIFF
Sum all CODEDIFF under each unique MRC and CATEGORY
I've played with using a DISTINCT, but can't construct the query to
work with any success at all.
Thank you one and all to any insight I can be given!
I have a single table with the following fields:
CLASS
CATEGORY
READDIFF
CODE
DATE
Before I go to far, I should explain one thing: CLASS, CATEGORY, and
CODE are hierarchically related; CODE being between 1 - 10000 and the
lowest child, CATEGORY being the parent of code and having 3
variations, and CLASS being the parent of CATEGORY and having 6
variations. Eventually I would like to display 18 lines of data (6
CLASS with 3 CATEGORY each), with the CODES being grouped together
under each CLASS and CATEGORY and used as unique identifiers to sum
READDIFF on each line. Example:
Note: this data also includes the field DATE, not shown here, which is
explained further below)
CLASS CATEGORY CODE READDIFF
1 1 1 10
1 1 2 15
1 1 3 20
1 2 4 10
1 2 5 7.5
1 2 6 5
1 3 7 10
1 3 8 5
1 3 9 2
2 1 10 10
2 1 11 50
....
6 1 18 75
would be displayed as:
CLASS CATEGORY SumOfREADDIFF
1 1 17
1 2 22.5
1 3 17
2 1 70
....
6 1 75
The above is what I'm trying to achieve.
I need to find some way, either in one query or in a thousand
subqueries, to return what I had outlined above. However, the
additional field of DATE will also need to be used to set boundaries
for summing READDIFF. Ie., sum all READDIFF between 1/1/1900 and
1/1/1901, but exclude anything before or after.
Additionally, there are many instances of the same CODE, as each CODE
has had multiple readings put into the database at different times.
Trying to group together CODE (which seems the simple solution) gives
me problems because each CODE has a unique time and date and also a
different READDIFF. Example:
CODE READDIFF DATE
1 10 1/1/1900
1 5 1/1/1901
1 2 1/1/1902
So trying to do a simple GroupBy on the CODE and a Sum of READDIFF
still results in three unique lines due to the DATE, except where of
course there are two or more DATE that are the same. Unfortunately,
DATE must be included so that the timelines can be established. This
seems to be a flaw (as far as with what I want ot have happen in
access) that constricts me to having to perform a GROUP BY on DATE
since I am performing a SUM on READDIFF and a GROUP BY on CODE. I do
not want to group DATE together, but merely use it as a filter.
Using the simply GROUP BY and SUM functions, I end up with a result
that is approximately 25,000 lines long, rather than the 18 I am
seeking.
Best I can explain in text is to show:
Each unique MRC
Each unique CATEGORY under each MRC
Group together all CODE which are the same
Sum all READDIFF for each grouped CODE as CODEDIFF
Sum all CODEDIFF under each unique MRC and CATEGORY
I've played with using a DISTINCT, but can't construct the query to
work with any success at all.
Thank you one and all to any insight I can be given!