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);
     
  • 相关阅读:
    leetcode 17 Letter Combinations of a Phone Number
    剑指offer 数字翻译成字符串
    剑指offer 把数组排成最小的数
    剑指offer 整数中1出现的次数(从1到n整数中1出现的次数)
    剑指offer 数据流中的中位数
    RNN, LSTM, GRU cells
    剑指offer 最小的K个数
    PWA-网络
    PWA-缓存
    2018 总结
  • 原文地址:https://www.cnblogs.com/yanchaohui/p/10042280.html
Copyright © 2011-2022 走看看