我正在尝试创建一个包含2000多个列的View表,并且select语句中声明的属性的95%也是select语句子查询。
这是我正在尝试做的:表A = 100列的主表表C = 10列的子表
表C将联接表A。但不是A的100列+ C的10列,而是A +的100列(表中的每行10 * fk = pk,最大为200)从C。
这是我的示例代码:
select
A.*
,
(select C.property where C.propertyNumber = 1 and C.propertyFk = A.propertyIdPk) as property1,
(select C.property where C.propertyNumber = 2 and C.propertyFk = A.propertyIdPk) as property2,
(select C.property where C.propertyNumber = 3 and C.propertyFk = A.propertyIdPk) as property3,
(select C.property where C.propertyNumber = 4 and C.propertyFk = A.propertyIdPk) as property4,
(select C.property where C.propertyNumber = 5 and C.propertyFk = A.propertyIdPk) as property5,
(select C.property where C.propertyNumber = 6 and C.propertyFk = A.propertyIdPk) as property6,
(select C.property where C.propertyNumber = 7 and C.propertyFk = A.propertyIdPk) as property7,
(select C.property where C.propertyNumber = 8 and C.propertyFk = A.propertyIdPk) as property8,
(select C.property where C.propertyNumber = 9 and C.propertyFk = A.propertyIdPk) as property9,
(select C.property where C.propertyNumber = 10 and C.propertyFk = A.propertyIdPk) as property10
from [schema].table A
left join [schema].table C on A.propertyIdPk = C.propertyFk
where C.propertyFk = A.propertyIdPk
还有另一种方法可以做到这一点,或者我做错了吗?
抱歉,听起来确实需要重新考虑架构设计。在人们放置了太多FK之前,我已经看到了此错误,但总是会回到架构设计问题。