Sum for multiple date ranges in a single call?

前端 未结 10 1801
有刺的猬
有刺的猬 2021-02-14 10:36

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:40

    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);
    

提交回复
热议问题