在安大略省,每位居民都获得一个健康卡号(HCN)。 在我们医院,为患者分配了病历号(MRN)。
我要查找一个实例,其中一个HCN出现在多个MRN上(这可能是由职员创建新的MRN导致的,即使患者/ HCN已经存在一个新的MRN也是如此。)
我希望输出仅列出创建的每个“重复” MRN的一个示例,以及其他数据,以便就是否合并记录做出良好,快速的决定(例如:生日,姓名,地址字段) ,电子邮件地址)。
我的表格包括:
我正在使用Microsoft Access,并已建立关系。我尝试了一些不同的代码,但可以使用一些帮助。我仍在学习SQL,现在还无法正确使用它。
这是Access生成的基准代码:
SELECT [HCN, Mri Urn].[Edited HCN], [MRN, Name, DOB].[Medical Record],
[MRN, Name, DOB].Name, [MRN, Name, DOB].Birthdate,
[Pat Address, Adm Urn].[Pat City], [Pat Address, Adm Urn].[Pat Street],
[Pat Address, Adm Urn].[Pat Street2], [Pat Address, Adm Urn].[Pat Email],
[Pat Address, Adm Urn].[Pat Home Phone]
FROM [Pat Address, Adm Urn]
INNER JOIN ([MRN, Name, DOB]
INNER JOIN ([HCN, Mri Urn]
INNER JOIN [ADM's Mri Urn-Adm Urn link]
ON [HCN, Mri Urn].Urn = [ADM's Mri Urn-Adm Urn link].[Mri Urn])
ON [MRN, Name, DOB].[Medical Record] = [ADM's Mri Urn-Adm Urn link].[Mri Urn])
ON [Pat Address, Adm Urn].Urn = [ADM's Mri Urn-Adm Urn link].Urn
ORDER BY [HCN, Mri Urn].[Edited HCN],
[MRN, Name, DOB].[Medical Record],
[MRN, Name, DOB].Name,
[MRN, Name, DOB].Birthdate,
[Pat Address, Adm Urn].[Pat City],
[Pat Address, Adm Urn].[Pat Street],
[Pat Address, Adm Urn].[Pat Street2],
[Pat Address, Adm Urn].[Pat Email],
[Pat Address, Adm Urn].[Pat Home Phone];
答案 0 :(得分:0)
由于它们的命名,您的表很难遵循:)我不确定这是否是您的意思(没有任何示例数据会更难理解):
SELECT
[HCN, Mri Urn].[Edited HCN],
[MRN, Name, DOB].[Medical Record],
[MRN, Name, DOB].Name,
[MRN, Name, DOB].Birthdate,
[Pat Address, Adm Urn].[Pat City],
[Pat Address, Adm Urn].[Pat Street],
[Pat Address, Adm Urn].[Pat Street2],
[Pat Address, Adm Urn].[Pat Email],
[Pat Address, Adm Urn].[Pat Home Phone]
FROM [Pat Address, Adm Urn]
INNER JOIN([MRN, Name, DOB]
INNER JOIN([HCN, Mri Urn]
INNER JOIN [ADM's Mri Urn-Adm Urn link]
ON [HCN, Mri Urn].Urn = [ADM's Mri Urn-Adm Urn link].[Mri Urn])
ON [MRN, Name, DOB].[Medical Record] = [ADM's Mri Urn-Adm Urn link].[Mri Urn])
ON [Pat Address, Adm Urn].Urn = [ADM's Mri Urn-Adm Urn link].Urn
where [ADM's Mri Urn-Adm Urn link].Urn in
(select urn from [ADM's Mri Urn-Adm Urn link]
group by URN having count(*) > 1)
ORDER BY [HCN, Mri Urn].[Edited HCN],
[MRN, Name, DOB].[Medical Record],
[MRN, Name, DOB].Name,
[MRN, Name, DOB].Birthdate,
[Pat Address, Adm Urn].[Pat City],
[Pat Address, Adm Urn].[Pat Street],
[Pat Address, Adm Urn].[Pat Street2],
[Pat Address, Adm Urn].[Pat Email],
[Pat Address, Adm Urn].[Pat Home Phone];