Interbase 2020 error: Column Unlnown

эта производная таблица(derived table) правильно отображает только записи первого подзапроса (select ... from recs) как в Interbase 2020, так в Firebird3 :

select
           s.goods_id,
           cast(0 as float)as inc,
           sum(s.qnt) as sale,
           cast(0 as float)as writeoff
           from recs s
           where cast(s.recsdate as date)<='01.12.22'
           group by s.goods_id
      union all
      select
         g.goods_id,
         cast(0 as float),
         sum(g.qnt)as sale,
         cast(0 as float)
            from recg g
            where cast(g.recgdate as date)<='01.12.22'
            group by g.goods_id
    
      union all
      select
           ch.goods_id,
           cast(0 as float),
           cast(0 as float),
           sum(ch.qnt) as writeoff
            from reccham ch
            where cast(ch.chamdate as date)<='01.01.2022'
            group by ch.goods_id

А этот запрос, который содержит производную таблицу, в Interbase 2020 возвращает ошибку:

Error at line 1. Dynamic SQL Error: Error at line 1. sql error code=-206. Column unknown INC.

Как будто пробовал все варианты правильного написания алиасов но всеравно не смог обойти ошибку:

SELECT
          goods_id,
          coalesce(sum(inc),0)as incomes,
          coalesce(sum(sale),0) as sales, 
          coalesce(sum(writeoff),0) as writeoff,
          sum(coalesce(inc,0)-coalesce(sale,0)-coalesce(writeoff,0))  as endqnt
        FROM(
      select
           s.goods_id,
           cast(0 as float)as inc,
           sum(s.qnt) as sale,
           cast(0 as float)as writeoff
           from recs s
           where cast(s.recsdate as date)<='01.12.22'
           group by s.goods_id
      union all
      select
         g.goods_id,
         cast(0 as float),
         sum(g.qnt)as sale,
         cast(0 as float)
            from recg g
            where cast(g.recgdate as date)<='01.12.22'
            group by g.goods_id
    
      union all
      select
           ch.goods_id,
           cast(0 as float),
           cast(0 as float),
           sum(ch.qnt) as writeoff
            from reccham ch
            where cast(ch.chamdate as date)<='01.01.2022'
            group by ch.goods_id) dt1
       group by goods_id

p.s. qnt поля типа float, date поля типа timestamp.

UPDATE1: Извиняюсь- код производной таблицы (dt1) правильно отображает все записи как в Interbase 2020, так в Firebird3.


Ответы (0 шт):