访问:“交叉表” 非数值数据的查询效果
我正在使用 Access 2007,需要帮助创建查询。 如果这太长了,抱歉! 我认为越详细越好理解。 我不是程序员——我希望有人能提供帮助。
我需要知道如何将非数字数据折叠/汇总/汇总到共享特征/值的单行中。 我想要的是像交叉表查询,因为我希望来自不同行的唯一单元格值在沿着一行的列中旋转/显示该共享/通用值。 但是,我的数据不是数字,它需要 alpha 列标题,而交叉表禁止这样做。
数据:
- Badge_code 24 在 3 个地点生成:110、210 和 320(代表芝加哥、罗克福德和圣路易斯)
- Badge_code B9 在 2 个地点生成:110 和 280(芝加哥和皮奥里亚)
- 徽章_代码 C1 位于 3 个位置:200 和 210(印第安纳波利斯和罗克福德)
每个徽章_代码-位置组合位于单独的行中,总共 8 行。 徽章代码的数量可以/将会增加。
我尝试过的查询:
Count(tbl_BadgeType.Badge_type_number) AS CountOfBadge_type_number
SELECT tbl_BadgeType.Badge_code
FROM tbl_BadgeType
GROUP BY tbl_BadgeType.Badge_code
PIVOT tbl_BadgeType.Location_production;
Badge_type_number 是用于标识每个徽章代码位置使用组合的主键。
结果:
Badge Code 110 200 210 280 320
24 1 1 1
B9 1 1
C1 1 1
列标题是数字,无法更改为交叉表中的位置名称,我想要“是”而不是“1”。 (显然,它们是 1,因为它是交叉表中的计数函数,我实际上并不需要...)
所需结果:
Badge Code Chicago Indianapolis Rockford Peoria St. Louis
24 Yes No Yes No Yes
B9 Yes No No Yes No
C1 No Yes Yes No No
问题/问题:
- 交叉表从最严格的意义上来说,查询并不是我所需要的,但我不知道如何模拟它的“汇总”效果。 这就是 6 页的晦涩难懂和 1 页的清晰有用之间的区别。
- 如果交叉表是的方法,那么我不知道如何将“1”值显示为“是”。 我已在其他查询和报告中使用 IIF 语句将 1/0 值“转换”为“是/否”,但无法弄清楚在该查询或其报告中放置 IIF 的位置。
这有道理吗? 我是不是要求太多了? 我还有希望吗? :^)
I am using Access 2007 and need help creating a query. If this is crazy long, sorry! I figure the more details the better understanding. I am not a programmer--I hope someone will help.
I need to know how to collapse/summarize/roll up non-numeric data into a single row that shares a characteristic/value. What I want is like a crosstab query because I want unique cell values from different rows pivoted/displayed in columns along one row for that shared/common value. However, my data isn't numeric and it requires alpha column headings, which crosstabs prohibit.
THE DATA:
- Badge_code 24 is produced in 3 locations: 110, 210, and 320 (represents Chicago, Rockford, and St. Louis)
- Badge_code B9 in 2 locations: 110, and 280 (Chicago and Peoria)
- Badge_code C1 in 3 locations: 200 and 210 (Indianapolis and Rockford)
Each badge_code-location combination is in a separate row, 8 rows total.
The number of badge codes can/will grow.
THE QUERY I'VE TRIED:
Count(tbl_BadgeType.Badge_type_number) AS CountOfBadge_type_number
SELECT tbl_BadgeType.Badge_code
FROM tbl_BadgeType
GROUP BY tbl_BadgeType.Badge_code
PIVOT tbl_BadgeType.Location_production;
Badge_type_number is the primary key used to id each badge code-location use combo.
RESULT:
Badge Code 110 200 210 280 320
24 1 1 1
B9 1 1
C1 1 1
The column headings are numeric and can't be changed to location names in crosstabs and I want a "Yes" instead of a "1". (Obviously, they're 1s because it's a count function in the crosstab, which I don't really need...)
DESIRED RESULT:
Badge Code Chicago Indianapolis Rockford Peoria St. Louis
24 Yes No Yes No Yes
B9 Yes No No Yes No
C1 No Yes Yes No No
PROBLEM/QUESTIONS:
- A crosstab query in its strictest sense is not quite what I need, but I do not know how to simulate its "roll up" effect. It's the difference between 6 pages of obscurity and 1 page of useful clarity.
- If a crosstab is the way to go, then I can't figure out how to get the "1" values to be displayed as a "Yes". I've used IIF statements in other queries and reports to "translate" 1/0 values to "Yes/No" but can't figure out where to put the IIFs in this query or its report.
Is this making sense? Am I asking too much? Is there hope for me? :^)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哇! 我没想到这么快就有答案。
以下是 tbl_BadgeTypes 相关字段的结构和示例数据:
徽章代码实际使用的位置位于 tbl_TokenInstance 中(令牌的每个实例 - 徽章、ID 等一行。徽章代码可能被不同的位置使用;它们不是排他性的:
最后,生产站点编号和描述的源列表位于 list_ProductionSite 中:
Wow! I wasn't expecting an answer so soon.
Here's the structure and sample data of pertinent fields of tbl_BadgeTypes :
The locations where a badge code is actually USED is in tbl_TokenInstance (a row for each instance of a token--badge, ID, etc. A badge code may be used by different locations; they're not exclusive. Pertinent data is:
Last, the source list of production site numbers and descriptions is in list_ProductionSite:
好的,等待对我上面留下的评论的回复,我可以建议一些部分解决方案(可能会产生更清晰的解决方案,具体取决于您的表格的外观):
问题#1:数字到文本
如果您有一个可以将 [Location_product] 与“芝加哥”等字符串匹配的表,而不是内部联接即可使“110”显示为“芝加哥”。 您尝试的查询的第三行将变成类似以下内容:
然后,您只需在 L.LocationName 或任何实际文本上进行交叉制表。
问题#2:“1”改为“Yes”
一般来说,您只需交换 vb iif 表达式即可将“1”更改为“Yes”,
您需要更改“Count( )”更改为查询顶行中的“Max()”或“Min()”,还可能进行其他更改,具体取决于数据的外观。
OK, so pending responses to the comments I left above, I can suggest some partial solutions (cleaner solutions may result, depending on what your table looks like):
Problem #1: Numbers to Text
If you have a table that can match [Location_production] to strings like "Chicago," than an inner join is all you need to make '110' appear as "Chicago." The third line of the query you tried would turn into something like:
You would then just crosstab on L.LocationName or whatever the actual text is.
Problem #2: "1" to "Yes"
Generally speaking, you could just swap a vb iif expression in to change the "1"s to "Yes"s
You would need to change "Count()" to "Max()" or "Min()" in the top line of your query and possibly other changes, depending on what your data looks like.