zoukankan      html  css  js  c++  java
  • sql group by sum

    1.表字段如下图,要求:分区计算总处数,总面积,已处理数,已处理面积,未处理数,未处理面积

     2.计算结果如下:

     3.sql如下:知识点:sum后的case可以根据A列状态,来计算B列的值。

    sum(case when sfcl='否'then mjm else 0 end) wcltbmj
     1 select max(xzqmc2) qymc,0 as hzbs,
     2 sum(mjm) as bhmj,
     3 count(sfcl) as bhs,
     4 sum(case when sfcl='是'then 1 else 0 end) ycltbs ,
     5 sum(case when sfcl='是'then mjm else 0 end) ycltbmj,
     6 sum(case when sfcl='否'then 1 else 0 end) wcltbs ,
     7 sum(case when sfcl='否'then mjm else 0 end) wcltbmj
     8 from zz_ygyswftb where pcsid = #{pcid} group by xzqmc2
     9 union
    10 select '萍乡' qymc,1 as hzbs,
    11 sum(mjm) as bhmj,
    12 count(sfcl) as bhs,
    13 sum(case when sfcl='是'then 1 else 0 end) ycltbs ,
    14 sum(case when sfcl='是'then mjm else 0 end) ycltbmj,
    15 sum(case when sfcl='否'then 1 else 0 end) wcltbs ,
    16 sum(case when sfcl='否'then mjm else 0 end) wcltbmj
    17 from zz_ygyswftb where pcsid = #{pcid}
  • 相关阅读:
    Elasticsearch 结构化搜索
    KMP 算法
    ElasticSearch 配置
    C++ 入门
    Spark 基础操作
    HBase 与 MapReduce 集成
    iOS面试相关
    iOS开发值得学习的Demo
    Mac系统安装MyEclipse
    linux安装tomcat
  • 原文地址:https://www.cnblogs.com/fxx5/p/14365576.html
Copyright © 2011-2022 走看看