小编典典

“ MOUNT1”在使用的上下文中无效

sql

我正在DB2中执行以下查询:

select  
  SUM (orders.totalproduct
      +orders.TOTALTAX
      +orders.totalshipping
      -orders.totaladjustment) as amount1 
from 
  orders  
where 
  amount1>10000

查询没有执行,我得到了这个异常:

“ AMOUNT1”在使用上下文中无效。SQLCODE = -206,SQLSTATE = 42703,DRIVER = 3.64.96
SQL代码:-206,SQL状态:42703

我究竟做错了什么?


阅读 190

收藏
2021-04-14

共1个答案

小编典典

您不能在DB2中同时创建和使用amount1。

试试这个:

 select * from (
 select SUM (orders.totalproduct+orders.TOTALTAX+orders.totalshipping- orders.totaladjustment) as amount1 from orders 
 ) tmp where amount1>10000

或这个:

select SUM (orders.totalproduct+orders.TOTALTAX+orders.totalshipping-  orders.totaladjustment) as amount1 from orders 
having  SUM (orders.totalproduct+orders.TOTALTAX+orders.totalshipping-orders.totaladjustment)>10000
2021-04-14