Bumped by Community user
    Bumped by Community user
    Bumped by Community user
4 Corrected spelling, grammar and punctuation to make the question easier to understand.
source | link

Getting sum result for last year devideddivided quarterly

I am trying to get the financial data grouped by each quarter of last year and also grouped by the last three weeks.

Also, if it is possible, I want to have the type as a separate column with the type as the header.

Getting sum result for last year devided quarterly

I am trying to get the financial data grouped by each quarter of last year and also grouped by last three weeks.

Also if it is possible to have the type as separate column with the type as the header.

Getting sum result for last year divided quarterly

I am trying to get financial data grouped by each quarter of last year and also grouped by the last three weeks.

Also, if it is possible, I want to have the type as a separate column with the type as the header.

3 Removing sql-server tag as this is PL/SQL
source | link

Select to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') ||'-'|| to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY') AS Month,

Select 
  to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') 
    || '-'
    || to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY') AS Month,

  case
     when (ap.asset = 2 or AP.ASSET_TYPE not like 'CFTD%' and
          AP.ASSET_TYPE not like 'CASH%' and AP.ASSET_TYPE != 'FTL') then
      'AUM'
     when (AP.ASSET_TYPE like 'CFTD%') then
      'Depostis'
     when (AP.ASSET_TYPE like 'CASH%') then
      'Cash'
     when (AP.ASSET_TYPE = 'FTL') then
      'Loan'
   end as Type,

   sum(ABS(AP.Eval_Market_Value)) as Total

from (select p.account, p.open_date as Open_Date, ac.description as RM, s.*


from (select p.account,
           p.open_date    as Open_Date,
           ac.description as RM,
           s.*

      FROM k$portfolio p, k$client k
      LEFT JOIN k$client_role cr
        ON cr.client = k.id
       AND cr.role = 136
      LEFT JOIN k$actors ac
        ON cr.actor = ac.id,
     table(gtw$reporting.Statement(p.id,
                                      2,
                                      trunc(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1)),
                                      trunc(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1)),
                                      1,
                                      1002,
                                      1,
                                      'USD')) s
     wHERE s.line_type = 'P'
       and k.id = p.client
       and p.id = s.portfolio
       and p.portfolio_type = 'C'
       and p.status = 1

    ) ap

group by to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') ||'-'|| to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY'),



group by to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') ||'-'|| to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY'),

      case
        when (ap.asset = 2 or AP.ASSET_TYPE not like 'CFTD%' and
             AP.ASSET_TYPE not like 'CASH%' and AP.ASSET_TYPE != 'FTL') then
         'AUM'
        when (AP.ASSET_TYPE like 'CFTD%') then
         'Depostis'
        when (AP.ASSET_TYPE like 'CASH%')  then
         'Cash'
     when (AP.ASSET_TYPE = 'FTL') then
         'Loan'
      end

Select to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') ||'-'|| to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY') AS Month,

  case
     when (ap.asset = 2 or AP.ASSET_TYPE not like 'CFTD%' and
          AP.ASSET_TYPE not like 'CASH%' and AP.ASSET_TYPE != 'FTL') then
      'AUM'
     when (AP.ASSET_TYPE like 'CFTD%') then
      'Depostis'
     when (AP.ASSET_TYPE like 'CASH%') then
      'Cash'
     when (AP.ASSET_TYPE = 'FTL') then
      'Loan'
   end as Type,

   sum(ABS(AP.Eval_Market_Value)) as Total

from (select p.account, p.open_date as Open_Date, ac.description as RM, s.*

      FROM k$portfolio p, k$client k
      LEFT JOIN k$client_role cr
        ON cr.client = k.id
       AND cr.role = 136
      LEFT JOIN k$actors ac
        ON cr.actor = ac.id,
     table(gtw$reporting.Statement(p.id,
                                      2,
                                      trunc(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1)),
                                      trunc(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1)),
                                      1,
                                      1002,
                                      1,
                                      'USD')) s
     wHERE s.line_type = 'P'
       and k.id = p.client
       and p.id = s.portfolio
       and p.portfolio_type = 'C'
       and p.status = 1

    ) ap

group by to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') ||'-'|| to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY'),

      case
        when (ap.asset = 2 or AP.ASSET_TYPE not like 'CFTD%' and
             AP.ASSET_TYPE not like 'CASH%' and AP.ASSET_TYPE != 'FTL') then
         'AUM'
        when (AP.ASSET_TYPE like 'CFTD%') then
         'Depostis'
        when (AP.ASSET_TYPE like 'CASH%')  then
         'Cash'
     when (AP.ASSET_TYPE = 'FTL') then
         'Loan'
      end
Select 
  to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') 
    || '-'
    || to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY') AS Month,

  case
     when (ap.asset = 2 or AP.ASSET_TYPE not like 'CFTD%' and
          AP.ASSET_TYPE not like 'CASH%' and AP.ASSET_TYPE != 'FTL') then
      'AUM'
     when (AP.ASSET_TYPE like 'CFTD%') then
      'Depostis'
     when (AP.ASSET_TYPE like 'CASH%') then
      'Cash'
     when (AP.ASSET_TYPE = 'FTL') then
      'Loan'
   end as Type,

   sum(ABS(AP.Eval_Market_Value)) as Total

from (select p.account,
           p.open_date    as Open_Date,
           ac.description as RM,
           s.*

      FROM k$portfolio p, k$client k
      LEFT JOIN k$client_role cr
        ON cr.client = k.id
       AND cr.role = 136
      LEFT JOIN k$actors ac
        ON cr.actor = ac.id,
     table(gtw$reporting.Statement(p.id,
                                      2,
                                      trunc(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1)),
                                      trunc(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1)),
                                      1,
                                      1002,
                                      1,
                                      'USD')) s
     wHERE s.line_type = 'P'
       and k.id = p.client
       and p.id = s.portfolio
       and p.portfolio_type = 'C'
       and p.status = 1

    ) ap


group by to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'MM') ||'-'|| to_char(add_months(last_day(TO_DATE(&DTE,'YYYYMMDD')),-1), 'YYYY'),

      case
        when (ap.asset = 2 or AP.ASSET_TYPE not like 'CFTD%' and
             AP.ASSET_TYPE not like 'CASH%' and AP.ASSET_TYPE != 'FTL') then
         'AUM'
        when (AP.ASSET_TYPE like 'CFTD%') then
         'Depostis'
        when (AP.ASSET_TYPE like 'CASH%')  then
         'Cash'
     when (AP.ASSET_TYPE = 'FTL') then
         'Loan'
      end
2 Removing sql-server tag as this is PL/SQL
| link
1
source | link