我使用sum聚合函数和子查询生成记录,但别名在内部查询中不起作用 . 我的疑问是
select UPP.item_total,
(select sum(INN.item_value_afs) total_item_value_afs from
(select distinct INN.reg_no,INN.tpt_cuo_nam,INN.item_total,INN.item_value_afs
from sigtasad.customs_import_data INN where INN.reg_no=UPP.reg_no and INN.tpt_cuo_nam=UPP.tpt_cuo_nam)) total_item_value,
sum(UPP.code_tax_amount), UPP.cmp_nam from SIGTASAD.CUSTOMS_IMPORT_DATA UPP where
UPP.reg_no='38699' and UPP.company_tin='9003247336' group by
UPP.reg_no,UPP.tpt_cuo_nam,UPP.cmp_nam,UPP.item_total ;
此查询生成此错误:ORA-00904:“UPP” . “TPT_CUO_NAM”:无效的标识符
我想要这个结果!
2 回答
您的查询有很多错误和不良习惯 . 例如:
使用未定义的表别名限定列名 .
您正在按
select
中的列聚合 .您在具有
sum()
的子查询上使用sum()
.根据您显示的图片,您可能需要以下内容:
也许:
你内心的子查询
引用未连接的表(
upp
) . 它也没有别名,但问题会在以后出现 . 请注意,似乎还有一个类型nn.reg_no
而不是inn.reg_no
这里没有显示表格的结构,但修复问题意味着: