[英]inner select statement not registering as a single-group function… “not a single-group group function”
由於我使用的報告軟件,我必須將所有內容放在一個sql語句中以獲取報告。 但是,即使最終產品中只有1個結果,Oracle SQL似乎也不允許我創建具有單組結果的內部選擇。 (所有其他結果均為單組函數)。 這是我的SQL:
select
COUNT(*) as TOTAL_RXS,
SUM(rx_tx.brand_acquisition_cost) as TOTAL_COST,
SUM(case rx_tx.drug_dispensed
when 'B' then (rx_tx.brand_price - rx_tx.brand_discount)
when 'G' then (rx_tx.generic_price - rx_tx.generic_discount)
end)
as TOTAL_PRICE,
SUM(case rx_tx.drug_dispensed
when 'B' then (rx_tx.brand_price - rx_tx.brand_discount - rx_tx.brand_acquisition_cost)
when 'G' then (rx_tx.generic_price - rx_tx.generic_discount - rx_tx.brand_acquisition_cost)
end)
as TOTAL_PROFIT
, (select
SUM(tx_tp.balance_due_from_tp)
from eps2.tx_tp
join eps2.rx_tx on rx_tx.id = tx_tp.rx_tx_id
where 1=1
-- This results in CLAIM STATUS being 'F'
AND rx_tx.fill_date is not NULL
AND rx_tx.returned_date is not NULL
AND rx_tx.reportable_sales_date is NULL
AND (tx_tp.paid_status like '%PAID%'
OR tx_tp.paid_status like '%PART%') ) as TOTAL_RECEIVABLES
from eps2.vw_rx_summary join eps2.rx_tx
on vw_rx_summary.last_filled_rx_tx_id = rx_tx.id
-- where TRUNC(rx_tx.fill_date,'DD') = TRUNC(SYSDATE - 1,'DD')
誰能幫我? 提前致謝。
select COUNT(*) as TOTAL_RXS,
SUM(rx_tx.brand_acquisition_cost) as TOTAL_COST,
MAX(select
SUM(tx_tp.balance_due_from_tp) as total_receivables
from eps2.tx_tp
join eps2.rx_tx on rx_tx.id = tx_tp.rx_tx_id
where 1=1
AND (tx_tp.paid_status like '%PAID%'
OR tx_tp.paid_status like '%PART%') ) as total_receivables
為total_receivables
添加一個MAX()
以total_receivables
其掩蓋為聚合函數!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.