Sum for multiple date ranges in a single call?

前端 未结 10 1368
礼貌的吻别
礼貌的吻别 2021-02-14 11:03

I have the following query:

SELECT 
   SUM(\"balance_transactions\".\"fee\") AS sum_id 
   FROM \"balance_transactions\" 
   JOIN charges ON balance_transactions         


        
10条回答
  •  梦谈多话
    2021-02-14 11:27

    I am coming from oracle PL/ SQL back ground. In my opinion you can use below query to use it. My understanding is that if any transaction is happening on 19-NOV-2013 1.00 AM is always going to be in 19 Nov to 20 Nov bucket so We should not worry about range I have created below query. I hope so it will help you.

    SELECT DISTINCT account_id,
      TRUNC(created)
      ||' to '
      || (TRUNC(created)+1) period,
      SUM(FEE) over (partition BY account_id,TRUNC(created) ) sumid
    FROM balance_transactions a,
      charges b
    WHERE a.source =balance_id
    AND b.refunded =0
    AND b.invoice IS NOT NULL
    AND a.type     ='charge'
    ORDER BY TRUNC(created)
      ||' to '
      || (TRUNC(created)+1);
    

提交回复
热议问题