sql把有箱子的地方改成有箱子的地方

xmd2e60i  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(343)

这是我的密码。我遇到的问题是与拥有有关的。我不得不做一些更改来处理teradata中的sas代码,因此,我需要消除groupby,并且我必须使用where子句而不是having,保持它的相同条件。不幸的是,我被绊倒了,这就是为什么我要征求你的建议。

SELECT t1.COD_PRODT, 
      t1.COD_RESID_, 
      t1.COD_DIVISA, 
      t1.COD_ABI, 
      t1.COD_NDG, 
      t1.COD_KTO, 
      t1.COD_PAESE, 
      t1.DAT_SCA, 
      t1.DAT_ACC, 
      t1.DAT_EST, 

      (COUNT(t1.COD_ABI)) AS COUNT_of_COD_ABI
  FROM WORK.A_VE_ES_DB_ANAGR_CONTO_CT_TT t1
  GROUP BY t1.COD_ABI,
           t1.COD_KTO
  HAVING  (
         CASE WHEN  COUNT_of_COD_ABI > 1 AND t1.DAT_EST IS NOT NULL THEN 1
                   WHEN COUNT_of_COD_ABI > 1 AND t1.DAT_EST IS NULL THEN 0
                   WHEN COUNT_of_COD_ABI = 1 THEN 1
                   ELSE 0 END
         ) = 1
  ORDER BY COUNT_of_COD_ABI DESC,
           t1.COD_ABI,
           t1.COD_KTO,
           t1.COD_NDG

我做了类似的事情,但结果是,它消除了重复,而我需要把他们纳入分析以及。。。

where (COUNT_of_COD_ABI = 
    CASE 
        WHEN COUNT_of_COD_ABI> 1 AND P2.DAT_EST IS NOT NULL THEN 1
        WHEN COUNT_of_COD_ABI> 1 AND P2.DAT_EST IS NULL THEN 0
        WHEN COUNT_of_COD_ABI = 1 THEN 1
        ELSE 0
    end )

你能帮我解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题