使用布尔字段作为行标题的交叉表查询
我目前有一个看起来像这样的表结构(省略了一些细节):
ColumnName || Type
Date_Of_Job DateTime
Reparied_Service Boolean
Disconnect_Service Boolean
Relayed_Service Boolean
Reparied_Stopcock Boolean
Replaced_Stopcock Boolean
TPFNR_Repaired Boolean
TPFNR_Replaced Boolean
TPFNR_Capped Boolean
Poor_Pressure_Tested Boolean
Flow_Test Boolean
Meter_replaced Boolean
我希望能够显示的是一个交叉表查询,其中月份(Date_Of_Job)作为列标题和不同的作业类型作为行标题以及该月每个作业的计数。
像这样的事情:
==Job Type===========01=====02=====03 etc
Reparied_Service 5 20 30
Disconnect_Service 15 45 9
Relayed_Service 18 7 6
Reparied_Stopcock 18
Replaced_Stopcock 20
etc
我遇到的问题是每个作业类型都存储为布尔列,因为每个记录可以包含多个作业类型。例如,您可以为一条记录记录 Reparied_Stopcock 作业以及 Flow_Test。
有谁知道我如何在 Access 或 MS SQL 中执行此操作,哪一个并不重要。
I currently have a table structure that looks something like this(some details omitted):
ColumnName || Type
Date_Of_Job DateTime
Reparied_Service Boolean
Disconnect_Service Boolean
Relayed_Service Boolean
Reparied_Stopcock Boolean
Replaced_Stopcock Boolean
TPFNR_Repaired Boolean
TPFNR_Replaced Boolean
TPFNR_Capped Boolean
Poor_Pressure_Tested Boolean
Flow_Test Boolean
Meter_replaced Boolean
What I want to be able to show is a cross tab query with the month(Date_Of_Job) as the column headers and the different types of jobs as the row headers with the count of each job for that month.
So something like this:
==Job Type===========01=====02=====03 etc
Reparied_Service 5 20 30
Disconnect_Service 15 45 9
Relayed_Service 18 7 6
Reparied_Stopcock 18
Replaced_Stopcock 20
etc
The problem that I have is that the each job type is stored as a boolean column because each record can included multiple job type. For example you can log a Reparied_Stopcock job as well as a Flow_Test for the one record.
Does anyone know how I can do this in access or MS SQL, it doesn't really matter which one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 Date_Of_Job 值来自同一年,您可以基于 UNION 子选择进行 Access 交叉表查询。
Assuming Date_Of_Job values are from the same year, you can base an Access cross tab query on a UNION subselect.