包含聚合查询或子查询的表达式上的聚合函数

时间:2020-04-04 17:57:20

标签: aggregation

我得到了oracle代码,将其翻译为T-SQL之后,我仍在努力使其正确 这是代码(我尝试CTE但没有运气)

声明@p_comp_code varchar(2)='01' 声明@p_job_code varchar(6)='121603'

选择g_hldbk_amt-g_rls_amt sc_outstanding_amt 来自( 选择sum(isnull(vou_inv_amt,0))v_vou_amt

    ,Sum (isnull(vou_orig_hldbk_amt, vou_hldbk_amt)) 

      + sum ((isnull((select sum(isnull(vrd_rls_amt,0)) 
                from cmic.vourlsdet
               where vou_comp_code = vrd_comp_code
               and vou_num = vrd_vou_num
               and vrd_post_date is not null ),0))) g_hldbk_amt  /* error */

    ,sum((select isnull(sum(vrd_rls_amt),0)
            from cmic.vourlsdet
            where vou_comp_code = vrd_comp_code
             and vou_num = vrd_vou_num
             and VRD_POST_DATE is not null )) g_rls_amt /* right join on cmic.voucher_master did not solve the issue */


    ,sum(isnull(vou_tax_amt,0)) g_gst_amt

    ,sum(vou_orig_hldbk_amt) vou_orig_hldbk_amt

    ,sum(vou_hldbk_amt) vou_hldbk_amt

from cmic.voucher_master

其中vou_comp_code = @p_comp_code 和vou_job_code = notull(@ p_job_code,vou_job_code) 并且vou_cont_code不为null 并且VOU_POST_DATE不为null 和vou_status_code!='V' )

谢谢 埃德·德罗(Ed Dror)

0 个答案:

没有答案