查询语言.groupBy

函数原型

  1. public function order($mixExpr);

说明:参数支持字符串以及它们构成的一维数组,用法和 orderBy 非常相似。

用法如下

  1. # SELECT `test`.`tid` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`id`,`test`.`name`
  2. Db::table('test', 'tid as id,tname as value')->
  3. groupBy('id')->
  4. groupBy('name')->
  5. getAll();
  6. # SELECT `test`.`tid` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `post`.`id`
  7. Db::table('test', 'tid as id,tname as value')->
  8. groupBy('post.id')->
  9. getAll();
  10. # SELECT `test`.`tid` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY SUM(`test`.`num`)
  11. Db::table('test', 'tid as id,tname as value')->
  12. groupBy('{SUM([num])}')->
  13. getAll();
  14. # SELECT `test`.`tid` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`title`,`test`.`id`,concat('1234',`test`.`id`,'ttt')
  15. Db::table('test', 'tid as id,tname as value')->
  16. groupBy("title,id,{concat('1234',[id],'ttt')}")->
  17. getAll();
  18. # SELECT `test`.`tid` AS `id`,`test`.`tname` AS `value` FROM `test` GROUP BY `test`.`title`,`test`.`id`,`test`.`ttt`,`test`.`value`
  19. Db::table('test', 'tid as id,tname as value')->
  20. groupBy(['title,id,ttt', 'value'])->
  21. getAll();