字段名称似乎不会延续到交叉表查询中

时间:2018-05-10 14:31:58

标签: sql ms-access

我有一系列查询 - 数据从表到选择查询,然后是联合查询,然后是另一个选择查询,最后到交叉表。每个查询都在每一步都有效,直到我进入交叉表。此时,我收到一个错误,即原始表中的字段是必需的但不可用。

这是查询链:

首先选择查询,名为 HSICInfantsSummary

 SELECT 
      Dates.[Report type], Dates.Start, Dates.End, 
      HSICInfantsReport.CHILD_CONTACT_ID AS ID, 
      .....
   FROM ((HSICInfantsReport 
       INNER JOIN HSInterconceptionReport ON HSICInfantsReport.CHILD_CONTACT_ID = HSInterconceptionReport.CLIENTUNIQUEIDENTIFICATION)
       INNER JOIN HSDemographicsReport ON HSICInfantsReport.CHILD_CONTACT_ID = HSDemographicsReport.CONTACT_ID)
       INNER JOIN (Dates INNER JOIN [Active client list] ON Dates.[Report type] = [Active client list].[Report type]) ON HSICInfantsReport.CHILD_CONTACT_ID = [Active client list].ClientID;

这是一个名为保险明细的联盟查询:

select "Client" as type, CLIENTUNIQUEIDENTIFICATION as ID, Admin_Date, Insurance from HSInterconceptionReport 
union all select "Client", CONTACT_ID, admin_date, insurance from HSPPScreeningReport 
union all select "Client", CONTACT_ID, admin_date, insurance from HSPreconceptionReport 
union all select "Client", CLIENTUNIQUEIDENTIFICATION, AdminDate, HealthInsuranceTypesIDs from HSPrenatalScreeningReport
union all select "Infant", format(ID) & " - " & format(DOB) & " - " & birthorder, Admin_date, BabyInsurance  from HSICInfantsSummary 
UNION ALL select "Infant", format(ID) & " - " & format(DOB & " - " & birthorder), Admin_Date, BBYInsurance from HSPPInfantsSummary;

这将进入另一个名为保险摘要 - 客户

的选择查询
SELECT  
  [All participants summary].[report type],
  [Insurance detail].type, 
  [Insurance detail].ID, 
  .....
FROM [Insurance detail] 
  INNER JOIN [All participants summary] ON [Insurance detail].ID = [All participants summary].ID
GROUP BY  
  [All participants summary].[report type],
  [Insurance detail].type, 
  [Insurance detail].ID, 
  ....
HAVING ((([Insurance detail].type)="Client") AND (([Insurance detail].Admin_Date)=(select max(admin_date) from [insurance detail] T where T.id=[insurance detail].id)))
ORDER BY [Insurance detail].ID, [All participants summary].EnrolledDate;

此查询正常工作并提供预期结果。然后我想做一个数据列的交叉表:

TRANSFORM Count([Insurance summary - client].ID) AS CountOfID  
SELECT [Insurance summary - client].[report type]  
FROM [Insurance summary - client]  
GROUP BY [Insurance summary - client].[report type]  
PIVOT [Insurance summary - client].Insured;

这就是它破裂的地方。这个查询应该知道来自Insurance summarry - client的字段“ID”,但它似乎想要一直回到作为ID的原始源的表,并且找不到它需要的内容。错误消息是:

enter image description here

你能告诉我为什么会这样吗,更重要的是如何解决这个问题?

0 个答案:

没有答案