zoukankan      html  css  js  c++  java
  • 巧妙的运用group,count,order有利于统计

    $aAwardMem = $this->dao_raward->getAwardAndMem($where,array('award_cat asc','award_level asc'),false,false,false,'award_cat,award_level,count(id) as count',false,array('award_cat','award_level'));

    //$where = false, $order = 'id ASC', $pagesize = false, $offset = false, $count = false, $from = false, $join = false, $group = false

    这里先按照award_cat排序,再按照award_level排序。

    完了之后,对award_cat进行group操作,cat是类别,和award_level进行group操作。

    这样就将cat,level剥离出来了。

    成了一小组,一小组的数据,并且是有序的数据。

    最后获取自己想要的字段award_cat,award_level,以及他们的各小组的数量。count(id)。

    能够灵活的运用好他们,可以省去很多php的逻辑处理。

    数据如下:

    Array
    (
        [0] => Array
            (
                [award_cat] => 1
                [award_level] => 1
                [count] => 5
            )
    
        [1] => Array
            (
                [award_cat] => 2
                [award_level] => 1
                [count] => 11
            )
    
        [2] => Array
            (
                [award_cat] => 2
                [award_level] => 2
                [count] => 6
            )
    
        [3] => Array
            (
                [award_cat] => 2
                [award_level] => 3
                [count] => 7
            )
    
        [4] => Array
            (
                [award_cat] => 2
                [award_level] => 4
                [count] => 10
            )
    
        [5] => Array
            (
                [award_cat] => 2
                [award_level] => 5
                [count] => 10
            )
    
        [6] => Array
            (
                [award_cat] => 2
                [award_level] => 6
                [count] => 9
            )
    
        [7] => Array
            (
                [award_cat] => 2
                [award_level] => 7
                [count] => 7
            )
    
        [8] => Array
            (
                [award_cat] => 3
                [award_level] => 2
                [count] => 5
            )
    
        [9] => Array
            (
                [award_cat] => 4
                [award_level] => 3
                [count] => 5
            )
    
        [10] => Array
            (
                [award_cat] => 5
                [award_level] => 4
                [count] => 4
            )
    
        [11] => Array
            (
                [award_cat] => 6
                [award_level] => 6
                [count] => 6
            )
    
    )
  • 相关阅读:
    A1039 Course List for Student (25 分)
    A1101 Quick Sort (25 分)
    日常笔记6C++标准模板库(STL)用法介绍实例
    A1093 Count PAT's (25 分)
    A1029 Median (25 分)
    A1089 Insert or Merge (25 分)
    A1044 Shopping in Mars (25 分)
    js 验证
    根据string获取对应类型的对应属性
    HTML 只能输入数字
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/3796500.html
Copyright © 2011-2022 走看看