内部选择语句未注册为单组函数...“不是单组组函数”
Posted
技术标签:
【中文标题】内部选择语句未注册为单组函数...“不是单组组函数”【英文标题】:inner select statement not registering as a single-group function... "not a single-group group function" 【发布时间】:2014-02-26 18:16:18 【问题描述】:由于我使用的报告软件,我必须将所有内容都放在一个 sql 语句中以生成报告。但是,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')
谁能帮帮我? 提前致谢。
【问题讨论】:
您的查询缺少外部查询的from
语句。如果这不是完整的查询,请显示完整的查询。
对不起...我通过不包括查询的某些部分来增加简单性并保护公司 sql 代码资产。但这是完整的查询。谢谢。
我想称之为的这种“屏蔽”或类型转换似乎对我不起作用。它说“异常:java.sql.SQLException:ORA-00936:缺少表达式”
【参考方案1】:
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()
以将其屏蔽为聚合 函数!
【讨论】:
以上是关于内部选择语句未注册为单组函数...“不是单组组函数”的主要内容,如果未能解决你的问题,请参考以下文章