zoukankan      html  css  js  c++  java
  • sql查询一个字段不同值并返回

    sql

    SELECT COUNT(字段),分组字段,SUM(字段),SUM(字段) 
    FROM 表 GROUP BY 分组字段

    java

        EntityWrapper<ProjectEntity> pp= new EntityWrapper<ProjectEntity>();
        pp.eq("depcode", community);
        int proc = projectService.selectCount(pp);
            pp.setSqlSelect("COUNT(depcode) as pro01,SUM(budgetmoney) as pro01money,status,SUM(usemoney)AS pro01usemoney").groupBy("status");
            List<Map<String,Object>> obj=projectService.selectMaps(pp);
            
            // 定义下标数组
                    String[] indexStrList = {"01","02","03","04","05"};
                    List<String> indexList=Arrays.asList(indexStrList);
                    List<String> newIndexList = new ArrayList<>(indexList);
            JSONObject jsonObject = new JSONObject();
            for(Map<String,Object> m : obj){
                 if(newIndexList.indexOf(m.get("status")) != -1 ){
                // 对象的key
                    String key = "pro" + m.get("status");
                    jsonObject.put(key,m.get("pro01"));
                    jsonObject.put("pro" + m.get("status") + "money", m.get("pro01money"));
                    jsonObject.put("pro" + m.get("status") + "usemoney", m.get("pro01usemoney"));
                    newIndexList.remove(m.get("status"));
                 }
            }
            for(String str : newIndexList){
                jsonObject.put("pro" + str,0);
                jsonObject.put("pro" + str + "money", 0);
                jsonObject.put("pro" + str + "usemoney", 0);
            }
             maptos.put("pro",jsonObject);
     
  • 相关阅读:
    模拟ssh远程执行命令
    基于UDP协议的套接字编程
    TCP三次握手,四次挥手
    基于TCP协议的套接字编程
    osi七层协议
    Python之__class__.__module__,__class__.__name__
    异常处理
    单例模式
    类方法__setattr__,__delattr__,__getattr__
    反射(hasattr,getattr,delattr,setattr)
  • 原文地址:https://www.cnblogs.com/yanchaohui/p/10042280.html
Copyright © 2011-2022 走看看