<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ### GROUP 分組查詢 >[danger] 分組查詢,顧名思義就是按照組區分開,進行查詢,比如按照性別分組 > 注意!!! group by 后面分組的字段不能隨便加,比如 group by 'sex' 那么,查詢字段必須為 sex ### 按照性別分組查詢全部數學成績的平均分 ~~~ const { Sequelize } = app; // 按照性別分組查詢全班數學成績的平均分 const ret = await Student.findAll({ // 查詢字段要和分組字段一致!!!! attributes:['sex', [ Sequelize.fn('AVG', Sequelize.col('math')), 'math_avg' ] ], // 分組字段 group: ['sex'] }) SELECT `sex`, AVG(`math`) FROM `student` GROUP BY `sex`; [ { "sex": "女", "math_avg": "85.4286" }, { "sex": "男", "math_avg": "78.0000" } ] ~~~ ***** ### 按照性別分組,分別查詢全班同學數學成績平均分和總人數 ~~~ // 按照性別分組,分別查詢全班同學數學成績平均分和總人數 const ret = await Student.findAll( { attributes:[ 'sex', [Sequelize.fn('AVG', Sequelize.col('math')), 'match_avg'], [Sequelize.fn('COUNT', Sequelize.col('id')), 'total_student'] ], group: ['sex'] } ) SELECT `sex`, AVG(`math`) , COUNT(`id`) FROM `student` GROUP BY `sex`; [ { "sex": "女", "match_avg": "85.4286", "total_student": 7 }, { "sex": "男", "match_avg": "78.0000", "total_student": 5 } ] ~~~ ***** ### 按照地區分組,分別統計每個地區數學成績平均分 和 總人數,分數低于70分的同學不參與分組 ~~~ // 按照地區分組,分別統計每個地區數學成績平均分 和 總人數,分數低于70分的同學不參與分組 const ret = await Student.findAll( { attributes:[ 'address', [ Sequelize.fn('AVG', Sequelize.col('math')), 'math_avg' ], [ Sequelize.fn('COUNT', Sequelize.col('id')), 'total_student' ] ], where: { math: { [Op.gt]:70 } }, group: ['address'] } ) SELECT `address`, AVG(`math`) , COUNT(`id`) FROM `student` WHERE `math` > 70 GROUP BY `address`; [ { "address": "四川", "math_avg": "84.0000", "total_student": 2 }, { "address": "昆明", "math_avg": "90.0000", "total_student": 1 }, { "address": "潭州", "math_avg": "92.0000", "total_student": 1 }, { "address": "西涼", "math_avg": "82.0000", "total_student": 2 }, { "address": "貴州", "math_avg": "86.2500", "total_student": 4 } ] ~~~ ***** ### 按照地區分組,分別統計每個地區學生的數學平均分,分數低于70分的同學不參與分組,并且參與分組的人數不能少于2人 >[danger] 注意!!!where 和 having 的區別? > where 在分組之前進行限定,如果不滿足條件,則不參與分組 > having 在分組之后進行限定,如果不滿足結果,則不會被查詢出來 > where 后不可以帶上聚合函數判斷,having 后可以帶上聚合函數進行判斷 ~~~ await Student.findAll( { attributes:[ 'address', [Sequelize.fn('AVG', Sequelize.col('math')), 'math'], [Sequelize.fn('COUNT', Sequelize.col('id')), 'total'] ], where: { math: { [Op.gt]:70 } }, group: 'address', having: { total:{ [Op.gt]:2 } } }) SELECT `address`, AVG(`math`),COUNT(`id`) as total FROM `student` WHERE `student` > 70 GROUP BY `address` HAVING `total` > 2; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看