期待我的查询中的许多记录。我只得到一个

时间:2015-08-01 16:03:00

标签: sql sql-server select join view

我有一个查询,我试图将其他两个表中的值加到视图中。 父表称为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实体,并为每个限制正确计算分配和扩展。但我期待更多的源实体。

0 个答案:

没有答案