I'm relatively new to Access and am having trouble constructing a query that, to me, seems fairly complex. I have records that look like this: (call it Table1)
ID FacType UrbanRural
AR0001 TP U
AR0001 TP U
AR0001 TP R
AR0002 WL U
AR0002 WL R
AR0002 WL R
AR0002 WL R
AR0003 WL U
AR0004 WH R
And I want to transform them into a series of records that shows, for each ID, the FacType, the number of times the ID appears in the first table, the number of times the ID appears in the first table and has a "U" under "UrbanRural", and the number of times the ID appears in the first table with a "R" under "UrbanRural" (the number of "U"s plus number of "R"s will always be the total number; there are no other codes or Null values). So in the example, I would want my Table2 to look like:
ID FacType TotalUR TotalU TotalR
AR0001 TP 3 2 1
AR0002 WL 4 1 3
AR0003 WL 1 1 0
AR0004 WH 1 0 1
So I'm breaking down the steps and it seems like they are (in my "pidgin SQL", which may or may not look anything like actual SQL):
1. select distinct ID into Table2 from Table1
2. join Table2 and Table1 and add: FacType, count of UrbanRural equal to "U", count of UrbanRural equal to "R" and the sum of those last two fields.
But I can't quite figure out how to write that query, either in SQL or in the QBE pane. Can anyone help?
Thanks!
ID FacType UrbanRural
AR0001 TP U
AR0001 TP U
AR0001 TP R
AR0002 WL U
AR0002 WL R
AR0002 WL R
AR0002 WL R
AR0003 WL U
AR0004 WH R
And I want to transform them into a series of records that shows, for each ID, the FacType, the number of times the ID appears in the first table, the number of times the ID appears in the first table and has a "U" under "UrbanRural", and the number of times the ID appears in the first table with a "R" under "UrbanRural" (the number of "U"s plus number of "R"s will always be the total number; there are no other codes or Null values). So in the example, I would want my Table2 to look like:
ID FacType TotalUR TotalU TotalR
AR0001 TP 3 2 1
AR0002 WL 4 1 3
AR0003 WL 1 1 0
AR0004 WH 1 0 1
So I'm breaking down the steps and it seems like they are (in my "pidgin SQL", which may or may not look anything like actual SQL):
1. select distinct ID into Table2 from Table1
2. join Table2 and Table1 and add: FacType, count of UrbanRural equal to "U", count of UrbanRural equal to "R" and the sum of those last two fields.
But I can't quite figure out how to write that query, either in SQL or in the QBE pane. Can anyone help?
Thanks!