zoukankan      html  css  js  c++  java
  • case when语句的应用

    case when语句运用
     1 select b.cur_branch,
     2 count(p.conttract_id), 
     3 sum(case when p.aff_date is null then p.payable_money else 0 end),
     4 sum(case when p.aff_date is null and p.fee_item ='租金' then p.payable_money else 0 end),
     5 sum(case when p.aff_date is null and p.fee_item ='电费' then p.payable_money else 0 end),
     6 sum(case when p.aff_date is not null then 1 else 0 end),
     7 sum(case when p.aff_date is null then 1 else 0 end)
     8 from WG_PJHSB p, wg_jzmb b 
     9 where p.station_id = b.station_code
    10 group by b.cur_branch
    11 order by b.cur_branch

    运用1:sum(case when p.aff_date is null then p.payable_money else 0 end)

    累加票据金额

    运用2:sum(case when 条件语句l then 1 else 0 end)

    累加计数使用。

  • 相关阅读:
    部署nginx服务
    mysql主从配置
    LNMP+WordPress博客搭建
    CIFS(Samba)服务的使用
    NFS服务的使用
    LVM逻辑卷
    FTP学习
    文件处理+生成器
    内置函数
    Python3
  • 原文地址:https://www.cnblogs.com/hnarea/p/6044298.html
Copyright © 2011-2022 走看看