TRANSFORM Count(Details.Customer_ID) AS CountOfCustomer_ID
SELECT
Switch(
[Age] < 25, "Under 25",
[Age] >= 25 And [Age] <= 32, "Between 25 And 32",
[Age] >= 32 And [Age] <= 40, "Between 32 And 40",
[Age] >= 40 And [Age] <= 45, "Between 40 And 45",
[Age] > 45, "Over 45"
) AS Age_Range
FROM Details
INNER JOIN [Account Status] ON Details.Customer_ID = [Account Status].Customer_ID
WHERE ((([Account Status].Account_Status)='Active'))
GROUP BY Details.Age, [Account Status].Account_Status
PIVOT Details.site;
My results are counting Active accounts like this:
Age Range Site 1 Site 2 Site 3
----------------- ------ ------ ------
Under 25 1
Under 25 1
Between 25 And 32 1
Between 25 And 32 1
Between 25 And 32 1
Between 25 And 32 1
When it should be like this:
Age Range Site 1 Site 2 Site 3
----------------- ------ ------ ------
Under 25 2
Between 25 And 32 4
I have tried grouping by the Switch statement as well and it does not work. Please help.
The answers given by other’s are correct in concept. Here’s the SQL you can use that will work
If you want to simplify things using an inline query this is what will work