SQL 聚合函数 笔记

 

 

select ht_MaiF2,sum(ht_HTmoney) as '总金额' from tb_ht where ht_ISemergency='否' group by ht_maif2



select ht_MaiF2,(sum(ht_HTmoney)-sum(cast(ht_fk as decimal(18,2)))) as '未付款金额',

  count(ht_id) as '合同数',sum(ht_htmoney) as '总金额',

  sum(cast(ht_fk as decimal(18,2))) as '应付款',

  sum(cast(ht_sk as decimal(18,2))) as '已开票',

  (sum(ht_HTmoney)-sum(cast(ht_sk as decimal(18,2)))) as '未开票'

  from tb_ht
where ht_ISemergency='否'
group by ht_maif2 having sum(ht_HTmoney)!=sum(cast(ht_fk as decimal(18,2)))

过滤条件应该用having 字据跟在group by 后面

 

你可能感兴趣的:(sql)