I Have done a bit of database administration in other environments but am fairly new to access. I have a peculiar problem that I have been trying to solve for almost 10 hours now :banghead:
Any help on this would be really appreciated. I have searched existing threads to no avail.
When I run query 1 (Below) it returns one row with value 9,147,353. This is correct.
When I add a 'group by' (shown in query 2) it returns one row with value 9,143,612. INCORRECT!
I have tried grouping by different fields. All statements with a 'Group By' return a number of rows with 'cases' field always totaling 9,143,612. There are certainly 9,147,353 total cases in the base table.
Why should the total cases change when grouped??
QUERY 1
SELECT SUM(S2.Cases) as Cases
FROM
(
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthA as Month,
S.Cases * S.MonthASplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
UNION ALL
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthB as Month,
S.Cases * S.MonthBSplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
) S2
Query 2
SELECT SUM(S2.Cases) as Cases
FROM
(
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthA as Month,
S.Cases * S.MonthASplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
UNION ALL
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthB as Month,
S.Cases * S.MonthBSplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
) S2
Group By S2.Year
Using MS Access 2010 btw
Any help on this would be really appreciated. I have searched existing threads to no avail.
When I run query 1 (Below) it returns one row with value 9,147,353. This is correct.
When I add a 'group by' (shown in query 2) it returns one row with value 9,143,612. INCORRECT!
I have tried grouping by different fields. All statements with a 'Group By' return a number of rows with 'cases' field always totaling 9,143,612. There are certainly 9,147,353 total cases in the base table.
Why should the total cases change when grouped??
QUERY 1
SELECT SUM(S2.Cases) as Cases
FROM
(
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthA as Month,
S.Cases * S.MonthASplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
UNION ALL
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthB as Month,
S.Cases * S.MonthBSplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
) S2
Query 2
SELECT SUM(S2.Cases) as Cases
FROM
(
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthA as Month,
S.Cases * S.MonthASplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
UNION ALL
SELECT
S.ViewDescription,
S.CustomersID,
S.ProductsID,
S.Year,
S.Week,
S.MonthB as Month,
S.Cases * S.MonthBSplit as Cases
FROM SCPViews S WHERE S.Current = TRUE
) S2
Group By S2.Year
Using MS Access 2010 btw