How to Select and Order By columns not in Groupy By SQL statement - Oracle

后端 未结 3 1524
失恋的感觉
失恋的感觉 2021-01-01 08:27

I have the following statement:

SELECT  
    IMPORTID,Region,RefObligor,SUM(NOTIONAL) AS SUM_NOTIONAL
From 
    Positions
Where
    ID = :importID
GROUP BY 
         


        
3条回答
  •  一整个雨季
    2021-01-01 08:43

    I believe this is

    select
      IMPORTID,
      Region,
      Site,
      Desk,
      RefObligor,
      Sum(Sum(Notional)) over (partition by IMPORTID, Region, RefObligor) 
    from
      Positions
    group by
      IMPORTID, Region, Site, Desk, RefObligor
    order by
      IMPORTID, Region, RefObligor, Site, Desk;
    

    ... but it's hard to tell without further information and/or test data.

提交回复
热议问题