巧妙的运用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 ) )