• 查询聚合查询.aggregate
    • 记录数量 count
    • 平均值 avg
    • 最大值 max
    • 最小值 min
    • 合计 sum

    查询聚合查询.aggregate

    记录数量 count

    1. # 函数原型
    2. public function getCount($strField = '*', $sAlias = 'row_count', $bFlag = false);
    3. # SELECT COUNT(*) AS row_count FROM `test` LIMIT 1
    4. # int
    5. Db::table('test')->
    6. getCount()
    7. # SELECT COUNT(*) AS row_count FROM `test` LIMIT 1
    8. # int
    9. Db::table('test')->
    10. count()->
    11. get()->
    12. row_count;
    13. # SELECT COUNT(*) AS row_count2 FROM `test` LIMIT 1
    14. # int
    15. Db::table('test')->
    16. getCount('*', 'row_count2')

    平均值 avg

    1. # 函数原型
    2. public function getAvg($strField, $sAlias = 'avg_value', $bFlag = false);
    3. # SELECT AVG(`test`.`num`) AS avg_value FROM `test` LIMIT 1
    4. # int
    5. Db::table('test')->
    6. getAvg('num');
    7. # SELECT AVG(`test`.`id`) AS avg_value FROM `test` LIMIT 1
    8. # int
    9. Db::table('test')->
    10. avg('id')->
    11. get()->
    12. avg_value;
    13. # SELECT AVG(`test`.`num`) AS avg_value2 FROM `test` LIMIT 1
    14. # int
    15. Db::table('test')->
    16. getAvg('num', 'avg_value2');

    最大值 max

    1. # 函数原型
    2. public function getMax($strField, $sAlias = 'max_value', $bFlag = false);
    3. # SELECT MAX(`test`.`num`) AS max_value FROM `test` LIMIT 1
    4. # int
    5. Db::table('test')->
    6. getMax('num');
    7. # SELECT MAX(`test`.`id`) AS max_value FROM `test` LIMIT 1
    8. # int
    9. Db::table('test')->
    10. max('id')->
    11. get()->
    12. max_value;
    13. # SELECT MAX(`test`.`num`) AS max_value2 FROM `test` LIMIT 1
    14. # int
    15. Db::table('test')->
    16. getMax('num', 'max_value2');

    最小值 min

    1. # 函数原型
    2. public function getMin($strField, $sAlias = 'min_value', $bFlag = false);
    3. # SELECT MIN(`test`.`num`) AS min_value FROM `test` LIMIT 1
    4. # int
    5. Db::table('test')->
    6. getMin('num');
    7. # SELECT MIN(`test`.`num`) AS min_value FROM `test` LIMIT 1
    8. # int
    9. Db::table('test')->
    10. min('num')->
    11. get()->
    12. min_value;
    13. # SELECT MIN(`test`.`num`) AS min_value2 FROM `test` LIMIT 1
    14. # int
    15. Db::table('test')->
    16. getMin('num', 'min_value2');

    合计 sum

    1. # 函数原型
    2. public function getSum($strField, $sAlias = 'sum_value', $bFlag = false);
    3. # SELECT SUM(`test`.`num`) AS sum_value FROM `test` LIMIT 1
    4. # int
    5. Db::table('test')->
    6. getSum('num');
    7. # SELECT SUM(`test`.`num`) AS sum_value FROM `test` LIMIT 1
    8. # int
    9. Db::table('test')->
    10. sum('id')->
    11. get()->
    12. sum_value;
    13. # SELECT SUM(`test`.`num`) AS sum_value2 FROM `test` LIMIT 1
    14. # int
    15. Db::table('test')->
    16. getSum('num', 'sum_value2');