我有一个查询,我试图将其他两个表中的值加到视图中。 父表称为Limit.A Limit有许多Allocations。还有很多扩展。(这些是我想要总结的两个表格)。每条记录还有一个源实体。当我运行此查询时,我只有一个记录或源实体,当我期望更多。这是我的疑问:
Select distinct *,
convert(varchar(100), p.Limit ) AS keyfield
from
(
select distinct
se.Oid as SourceEntity,
l.oid as Limit ,
SUM(la.ARLimit) AS LAARLimit,
SUM(la.MTMLimit) AS LAMTMLimit,
SUM(la.Volume) AS LAMaxVolume,
SUM(la.MaxTenor) AS LAMaxTenor,
SUM(le.ARLimit) AS LEARLimit,
SUM(le.MTMLimit) AS LEMTMLimit,
SUM(le.Volume) AS LEMAxVolume,
SUM(le.MaxTenor) AS LEMaxTenor, SUM(la.ARLimit) + SUM(le.ARLimit) AS [ARLimit],
SUM(la.MTMLimit) + SUM(le.MTMLimit) AS [MTMLimit],
SUM(la.Volume) + SUM (le.Volume) AS [Volume],
SUM(la.MaxTenor) + SUM(le.MaxTenor) AS [MaxTenor]
from limit l
left join limitallocation la
on l.oid = la.limit
left join limitextension le
on l.oid = le.limit
left join
dbo.SourceEntity as se on la.SourceEntity = se.oid and le.SourceEntity = se.Oid
where se.oid is not null
GROUP BY l.Oid,se.Oid) as p
我只获得One Source实体,并为每个限制正确计算分配和扩展。但我期待更多的源实体。