访问中的单个表中的联合字段

时间:2018-01-03 17:42:17

标签: sql ms-access

当前表格如下:

Acct|Date|Rate Center_01|Charge_01|UOS_01|Rate Center_02|Charge 02|UOS_02|..out to set10
a   |1/1/1|01           |100      |  3   | 15           |  75     |6     |........
a   |1/2/1|04           |70       |  6   | 12           |  35     |12 
b   |2/2/2|03           |50       |  8   | 07           |  30     |15    |.........

我希望它看起来像:

Acct|Date|Rate Center|Charge|Units|
a   |1/1/1|01        |100   |3
a   |1/1/1|15        |75    |6
a   |1/2/1|04        |70    |6
a   |1/2/1|12        |35    |12 
b   |2/2/2|03        |50    |8
b   |2/2/2|07        |30    |15

我想确保帐户和日期仅显示当天分配的费率中心和单位。目前,我的查询是将同一帐户中不同日期发生的费率重复。有没有办法限制重复的东西?

SELECT [Account], [MRN], [AdmitDate], [DischDate], [UB_1] as [UB], [Rt Ctr Cd_1] as [Rate Center], [UOS_1] as [Units], [Charges_1] as [Charges] FROM [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_2], [Rt Ctr Cd_2], [UOS_2], [Charges_2] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_3], [Rt Ctr Cd_3], [UOS_3], [Charges_3] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_4], [Rt Ctr Cd_4], [UOS_4], [Charges_4] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_5], [Rt Ctr Cd_5], [UOS_5], [Charges_5] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_6], [Rt Ctr Cd_6], [UOS_6], [Charges_6] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_7], [Rt Ctr Cd_7], [UOS_7], [Charges_7] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_8], [Rt Ctr Cd_8], [UOS_8], [Charges_8] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_9], [Rt Ctr Cd_9], [UOS_9], [Charges_9] From [Inpatient Type 3]
Union Select [Account], [MRN], [AdmitDate], [DischDate], [UB_10], [Rt Ctr Cd_10], [UOS_10], [Charges_10] From [Inpatient Type 3]

0 个答案:

没有答案