给定数据看起来像
PLI_ID OWN_ID DCSF_ID SCH_NAME PREMIUM1 PREMIUM2 DESCRIPTION
901 2 1000 Dfe-School 1 86.40 7.20 Heads, Deps
902 2 1000 Dfe-School 2 403.30 8.40 Relief Bursar
903 2 1000 Dfe-School 3 327.00 8.40 £10.00
904 2 1000 Dfe-School 4 381.50 8.40 £11.00
905 2 1000 Dfe-School 5 152.60 8.40 Teaching staff
预期数据看起来像
School £10.00 £11.00 Heads, Deps Relief Bursar Teaching staff Total
Dfe-School 1
Dfe-School 2
Dfe-School 3
Dfe-School 4
Total [Pre-Total]
我不确定是否按照建议编写 Cross Tab 或 Cross Over 查询。如果需要更多解释,请告诉我。
我的查询使用了大约 6 个表,它看起来像这样:
选择 PolicyLine.PLI_POS_Id、Policy.POL_OWN_Id、Policy.POL_DCSF、School.SCH_Name、PolicyLine.PLI_Premium、CoverPremium.CPR_Premium、StaffCategory.SCA_Description FROM 学校 在 School.SCH_OWN_Id = Policy.POL_OWN_Id AND School.SCH_DCSF = Policy.POL_DCSF 上的内部加入政策 内部加入 PolicyLine 上 Policy.POL_Id = PolicyLine.PLI_POL_Id 内部连接 CoverOption ON PolicyLine.PLI_COP_Id = CoverOption.COP_Id 内部加入 CoverPremium ON CoverOption.COP_Id = CoverPremium.CPR_COP_Id AND Policy.POL_OWN_Id = CoverPremium.CPR_OWN_Id 右外连接 StaffCategory ON CoverOption.COP_SCA_Id = StaffCategory.SCA_