select ht_MaiF2,
 (sum(ht_HTmoney)-sum(cast(ht_fk as decimal(18,2)))) as 'ht_WFK',
 count(ht_id) as 'ht_Counts',
 sum(ht_htmoney) as 'ht_CountMoneys',
 sum(cast(ht_fk as decimal(18,2))) as 'ht_YFK', 
 sum(cast(ht_sk as decimal(18,2))) as 'ht_YKP',
 (sum(ht_HTmoney)-sum(cast(ht_sk as decimal(18,2)))) as 'ht_WKP' from tb_ht 
where ht_ISemergency='否'
 and ht_ISDelete='否' 
 and ht_FKMX='未归档' 
 and ht_ty=1 
 and ht_BeiZ='通过'
 and sum(ht_HTmoney)!=sum(cast(ht_fk as decimal(18,2)))
group by ht_maif2
报错的是这一句
 and sum(ht_HTmoney)!=sum(cast(ht_fk as decimal(18,2)))

解决方案 »

  1.   

    select ht_MaiF2,
     (sum(ht_HTmoney)-sum(cast(ht_fk as decimal(18,2)))) as 'ht_WFK',
     count(ht_id) as 'ht_Counts',
     sum(ht_htmoney) as 'ht_CountMoneys',
     sum(cast(ht_fk as decimal(18,2))) as 'ht_YFK', 
     sum(cast(ht_sk as decimal(18,2))) as 'ht_YKP',
     (sum(ht_HTmoney)-sum(cast(ht_sk as decimal(18,2)))) as 'ht_WKP' from tb_ht 
    group by ht_maif2
     having ht_ISemergency='否'
     and ht_ISDelete='否' 
     and ht_FKMX='未归档' 
     and ht_ty=1 
     and ht_BeiZ='通过'
     and sum(ht_HTmoney)!=sum(cast(ht_fk as decimal(18,2)))
      

  2.   

    ??
    HAVING sum(ht_HTmoney)!=sum(cast(ht_fk as decimal(18,2))) 
      

  3.   


    不行哟
    消息 8121,级别 16,状态 1,第 1 行
    HAVING 子句中的列 'tb_ht.ht_ISemergency' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
    消息 8121,级别 16,状态 1,第 1 行
    HAVING 子句中的列 'tb_ht.ht_ISDelete' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
    消息 8121,级别 16,状态 1,第 1 行
    HAVING 子句中的列 'tb_ht.ht_FKMX' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
    消息 8121,级别 16,状态 1,第 1 行
    HAVING 子句中的列 'tb_ht.ht_ty' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
    消息 8121,级别 16,状态 1,第 1 行
    HAVING 子句中的列 'tb_ht.ht_BeiZ' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
      

  4.   

    select ht_MaiF2,
     (sum(ht_HTmoney)-sum(cast(ht_fk as decimal(18,2)))) as 'ht_WFK',
     count(ht_id) as 'ht_Counts',
     sum(ht_htmoney) as 'ht_CountMoneys',
     sum(cast(ht_fk as decimal(18,2))) as 'ht_YFK', 
     sum(cast(ht_sk as decimal(18,2))) as 'ht_YKP',
     (sum(ht_HTmoney)-sum(cast(ht_sk as decimal(18,2)))) as 'ht_WKP' from tb_ht 
    where ht_ISemergency='否'
     and ht_ISDelete='否' 
     and ht_FKMX='未归档' 
     and ht_ty=1 
     and ht_BeiZ='通过'group by ht_maif2 having sum(ht_HTmoney)!=sum(cast(ht_fk as decimal(18,2)))
      

  5.   

    group by 的刷选条件写在having 子句中