Как запросить Oracle группировки? - PullRequest
0 голосов
/ 16 апреля 2020

У меня такая проблема, и я не знаю, как ее решить, вы можете мне помочь? t Запрос возвращает результат, который показан на фотографии, и я хочу, чтобы он отображался в одной строке вместо многих в зависимости от возраста.

https://imgur.com/a/OA6CBpa

 with x as (
  select ai.invoice_id, ai.invoice_num, ai.invoice_amount, ai.amount_paid,
    trial.entity_id, trial.acctd_amount, trial.entered_amount, trial.gl_date,
    aps.amount_remaining, aps.gross_amount, aps.due_date, aps.payment_status_flag,
    trial.gl_date - aps.due_date dni_opoznienia
  from ap_invoices_all ai,
    xla.xla_transaction_entities xte,
    (
      select nvl (tr.applied_to_entity_id, tr.source_entity_id) entity_id,
        tr.source_application_id application_id,
        sum (nvl (tr.acctd_unrounded_cr, 0)) - sum (nvl (tr.acctd_unrounded_dr, 0)) acctd_amount,
        sum (nvl (tr.entered_unrounded_cr, 0)) - sum (nvl (tr.entered_unrounded_dr, 0)) entered_amount,
        max(tr.gl_date) gl_date
      from xla.xla_trial_balances tr
      where 1=1
        and tr.definition_code = 'AP_200_1001'
        and tr.source_application_id = 200
        and tr.gl_date <= fnd_date.canonical_to_date('2019-12-13') -- Data KG
      group by nvl (tr.applied_to_entity_id, tr.source_entity_id),
        tr.source_application_id
    ) trial,
    ap_payment_schedules_all aps
  where 1=1
    and ai.invoice_id = 3568325
    and nvl(xte.source_id_int_1, -99) = ai.invoice_id
    and xte.ledger_id = 1001
    and xte.entity_code = 'AP_INVOICES'
    and xte.entity_id = trial.entity_id
    and xte.application_id = trial.application_id
    and ai.invoice_id = aps.invoice_id
)
select x.invoice_id, x.invoice_num, x.entity_id, x.acctd_amount, x.gl_date,
  x.amount_remaining, x.gross_amount, x.due_date, x.payment_status_flag,
  x.dni_opoznienia, aapl.days_start, aapl.days_to,
  case
    when x.dni_opoznienia between aapl.days_start and aapl.days_to then x.acctd_amount
    else 0
    end przedzial
from x,
  ap_aging_periods aap,
  ap_aging_period_lines aapl
where 1=1
and aap.period_name = 'TEST 5 okresow'
and aap.aging_period_id = aapl.aging_period_id

1 Ответ

0 голосов
/ 16 апреля 2020

Исходя из вашего комментария, я думаю, вам нужно ниже

select * from (select x.invoice_id, x.invoice_num, x.entity_id, x.acctd_amount, x.gl_date,
      x.amount_remaining, x.gross_amount, x.due_date, x.payment_status_flag,
      x.dni_opoznienia, aapl.days_start, aapl.days_to,
      case
        when x.dni_opoznienia between aapl.days_start and aapl.days_to then x.acctd_amount
        else 0
        end przedzial
    from x,
      ap_aging_periods aap,
      ap_aging_period_lines aapl
    where 1=1
    and aap.period_name = 'TEST 5 okresow'
    and aap.aging_period_id = aapl.aging_period_id)
    where przedzial > 0;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...