<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        mongodb的group簡析

        來源:懂視網 責編:小采 時間:2020-11-09 16:21:32
        文檔

        mongodb的group簡析

        mongodb的group簡析:mongodb的group簡析 數據如下 www.2cto.com { _id : 0, name : hexin0, value : 0, date : ISODate(2012-12-19T11:48:07.151Z), group : 0 } { _id : 1, name : hexin1, value : 1, date : ISODate
        推薦度:
        導讀mongodb的group簡析:mongodb的group簡析 數據如下 www.2cto.com { _id : 0, name : hexin0, value : 0, date : ISODate(2012-12-19T11:48:07.151Z), group : 0 } { _id : 1, name : hexin1, value : 1, date : ISODate

        mongodb的group簡析 數據如下 www.2cto.com { _id : 0, name : hexin0, value : 0, date : ISODate(2012-12-19T11:48:07.151Z), group : 0 } { _id : 1, name : hexin1, value : 1, date : ISODate(2012-12-19T11:48:07.151Z), group : 1 } { _id : 2, name :

        mongodb的group簡析

        數據如下 www.2cto.com

        { "_id" : 0, "name" : "hexin0", "value" : 0, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 1, "name" : "hexin1", "value" : 1, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        { "_id" : 2, "name" : "hexin2", "value" : 2, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 2 }

        { "_id" : 3, "name" : "hexin3", "value" : 3, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 4, "name" : "hexin4", "value" : 4, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        { "_id" : 5, "name" : "hexin5", "value" : 5, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 2 }

        { "_id" : 6, "name" : "hexin6", "value" : 6, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 7, "name" : "hexin7", "value" : 7, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        { "_id" : 8, "name" : "hexin8", "value" : 8, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 2 }

        { "_id" : 9, "name" : "hexin9", "value" : 9, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 10, "name" : "hexin10", "value" : 10, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        { "_id" : 11, "name" : "hexin11", "value" : 11, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 2 }

        { "_id" : 12, "name" : "hexin12", "value" : 12, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 13, "name" : "hexin13", "value" : 13, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        { "_id" : 14, "name" : "hexin14", "value" : 14, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 2 }

        { "_id" : 15, "name" : "hexin15", "value" : 15, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 16, "name" : "hexin16", "value" : 16, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        { "_id" : 17, "name" : "hexin17", "value" : 17, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 2 }

        { "_id" : 18, "name" : "hexin18", "value" : 18, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 0 }

        { "_id" : 19, "name" : "hexin19", "value" : 19, "date" : ISODate("2012-12-19T11:48:07.151Z"), "group" : 1 }

        需要實現下面sql :

        1

        select date as d_o_f , goup ,sum(value),count(*),avg(sum(value)/count(*))

        2

        from xx

        3

        where name like 'hexin%'

        4

        group by goup, date

        www.2cto.com

        1.定義分組的key

        1

        StringBuilder keyfun = new StringBuilder();

        2

        keyfun.append("function(d) {");

        3

        keyfun.append(" return { ");

        4

        keyfun.append(" goup : d.group ,");

        5

        keyfun.append(" d_o_f: d.date.getDay() ");

        6

        keyfun.append(" } ;");

        7

        keyfun.append(" }");

        2. 遍歷每個組的處理方式

        1

        StringBuffer reduce = new StringBuffer();

        2

        reduce.append("function ( curr, result) {");

        3

        reduce.append(" result.total += curr.value; ");

        4

        reduce.append(" result.count++;");

        5

        reduce.append("}");

        3. 計算平均數

        1

        StringBuffer finalize = new StringBuffer();

        2

        finalize.append("function(result){");

        3

        finalize.append(" var weekdays = [ '星期天', '星期一', '星期二',");

        4

        finalize.append(" '星期三', '星期四', ");

        5

        finalize.append(" '星期五', '星期六' ];");

        6

        finalize.append(" result.d_o_f = weekdays[result.d_o_f]; ");

        7

        finalize.append(" result.avg = Math.round(result.total / result.count); ");

        8

        finalize.append("}");

        4. 調用dao查詢

        1

        Group group = Group.keyFunction(keyfun.toString()).initial("count", 0).initial("total", 0)

        2

        .reduce(reduce.toString()).finalizeFunction(finalize.toString());

        3

        //調用自己封裝的dao來實現 , 并輸出結果

        4

        List> list = dao.group("c", Query.where("name").startWith("hexin"), group);

        5

        for (Map map : list) {

        6

        System.out.println(map);

        7

        }

        封裝的查詢條件 :

        www.2cto.com

        1

        { "$regex" : { "$regex" : "^hexin" , "$options" : "m"}}

        封裝的group命令

        01

        {

        02

        "group": {

        03

        "$keyf": "function(d) { return { goup : d.group , d_o_f: d.date.getDay() } ; }",

        04

        "$reduce": "function ( curr, result) {result.total += curr.value; result.count++;}",

        05

        "initial": {

        06

        "total": 0,

        07

        "count": 0

        08

        },

        09

        "finalize": "function(result){

        10

        var weekdays = [ '星期天', '星期一', '星期二','星期三', '星期四','星期五', '星期六' ];

        11

        result.d_o_f = weekdays[result.d_o_f];

        12

        result.avg = Math.round(result.total / result.count);

        13

        }",

        14

        "ns": "c",

        15

        "cond": {

        16

        "name": {

        17

        "$regex": {

        18

        "$regex": "^hexin",

        19

        "$options": "m"

        20

        }

        21

        }

        22

        }

        23

        }

        24

        }

        /////查詢結果

        {goup=0.0, d_o_f=星期三, total=63.0, count=7.0, avg=9.0}

        {goup=1.0, d_o_f=星期三, total=70.0, count=7.0, avg=10.0}

        {goup=2.0, d_o_f=星期三, total=57.0, count=6.0, avg=10.0}

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        mongodb的group簡析

        mongodb的group簡析:mongodb的group簡析 數據如下 www.2cto.com { _id : 0, name : hexin0, value : 0, date : ISODate(2012-12-19T11:48:07.151Z), group : 0 } { _id : 1, name : hexin1, value : 1, date : ISODate
        推薦度:
        標簽: mo 簡析 mongodb
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲中文字幕无码不卡电影| 国产99视频精品免费视频7| 亚洲中文久久精品无码| 窝窝影视午夜看片免费| 免费看国产一级特黄aa大片| 美女啪啪网站又黄又免费| 四虎永久成人免费影院域名| 怡红院亚洲红怡院在线观看| 亚洲福利视频一区二区| 一区二区三区免费精品视频| 亚洲中文字幕伊人久久无码| 久久国产免费直播| 亚洲日韩精品无码一区二区三区| 久久99精品免费一区二区| 亚洲av午夜福利精品一区 | h在线看免费视频网站男男| 日批日出水久久亚洲精品tv| 成人免费乱码大片A毛片 | 亚洲黄色免费电影| 久久天天躁狠狠躁夜夜免费观看| 亚洲人成网站免费播放| 亚洲精品国精品久久99热| 91免费国产视频| 亚洲av日韩av综合| 国产乱弄免费视频| 在线观看片免费人成视频播放| 亚洲国产一区在线| 午夜免费福利网站| 中文字幕手机在线免费看电影 | 国产好大好硬好爽免费不卡 | 国产aⅴ无码专区亚洲av麻豆 | 在线jyzzjyzz免费视频| av网站免费线看| 67pao强力打造67194在线午夜亚洲| 最近免费中文字幕视频高清在线看 | 久久久久成人片免费观看蜜芽| 亚洲精品综合在线影院| 亚洲第一网站男人都懂| 在线永久免费的视频草莓| 在线亚洲v日韩v| 亚洲精品视频在线观看免费 |