SELECT列表中的列或表达式无效

时间:2017-08-08 16:13:30

标签: sql odbc

我收到此错误:

  

[IBM] [System i Access ODBC Driver] [DB2 for i5 / OS] SQL0122 - 列CDSTYL或SELECT列表中的表达式无效。

当我尝试运行以下查询时。

CDSTYLCDCART00中的有效列。

我不确定问题是什么。 SQL是我试图从中获取数据的库存管理系统的一部分。

select 
    x.item,
    x.lot,
    sum(x.case_qty) lpn_inv_ttl,
    sum(x.carton_qty) carton_ttl,
    sum(x.sku_invn) sku_inv_ttl,
    sum(x.case_qty)+sum(x.carton_qty) - sum(x.sku_invn) inv_discrepany
from
    (select 
         IDSTYL as Item,
         IDBCHN as Lot,
         IDQTY as case_qty,
         0 sku_invn,
         0 as carton_qty
     from 
         idcase00
     where 
         IDSTAT in ('30', '50', '55', '60', '65', '90')

     union all

     select
         CDSTYL as Item,
         cdbchn as Lot,
         0 as case_qty,
         0 as sku_invn,
         sum(cdpaku) as carton_qty
     from 
         chcart00
     join 
         CDCART00 on chcasn = cdcasn
     where 
         chstat < '85'

     union all

     select 
         SKSTYL as Item, 
         SKBCHN as Lot,
         0 as case_qty,
         (SKAOHQ + SKUOHQ) AS sku_invn,
         0 as carton_qty
     from 
         SKINVN00) X
group by 
    x.item, x.lot
having 
    sum(x.case_qty) + sum(x.carton_qty) != sum(x.sku_invn)

1 个答案:

答案 0 :(得分:3)

您需要一个小组:

select CDSTYL as Item,
                            cdbchn as Lot,
                            0 as case_qty,
                            0 as sku_invn,
                            sum(cdpaku) as carton_qty
                            from chcart00
                            join CDCART00
                            on chcasn = cdcasn
                            where chstat < '85'
group by CDSTYL ,cdbchn