I have a Access 2010 database with a yes/no field for residing in the city limits or in the surrounding county. I wrote a SQL query to count how many people are in each category. How do I change the row names from Yes/No to "Reside in City" and "Reside in County" in the output table?
SELECT Person.ResideCity, Count(*) AS [Count]
FROM Person
GROUP BY Person.ResideCity;
ResideCity Count
Yes 10
No 23
答案 0 :(得分:0)
You can do this with an IIF
statement. Yes/No fields return -1 for yes and 0 for no. If you need to group by this field, you need the full expression in the GROUP BY
clause:
SELECT IIF(Person.ResideCity = -1, "Reside In City", "Reside In County") As ResideCity
, Count(*) AS [Count]
FROM Person
GROUP BY IIF(Person.ResideCity = -1, "Reside In City", "Reside In County");