分析一

$res = M('member')
->table('__MEMBER__ as a')
->join('__ORDER__ as b')
->field('a.id,b.order_sn,count(b.id) as total')
->where('b.receive_member_id = a.id')
->group('a.id')
->order('total desc')
->limit($page->firstRow, $page->listRows)
->select();

1. $res = M('member') ,$res = M('member a') ,$res = M('member as a') 意思相同

2.$res = M('member')->table('__MEMBER a')  , $res = M('member')->table('__MEMBER as a') 相同

分析二

$res = M('member_attest')
->table('__MEMBER_ATTEST__ a')
->join('__MEMBER__ b')
->join('__ORDER__ c')
->field('a.id,a.member_id,a.real_name,a.rank,b.mobile,count(c.id) as total')
->where('c.receive_member_id = b.id and b.id = a.member_id')->group('a.id')
->order('total desc')
->limit($page->firstRow, $page->listRows)
->select();

$res = M('member_attest')
->table('__MEMBER_ATTEST__ a')
->join('__MEMBER__ b ON b.id = a.member_id')
->join('__ORDER__ c')
->field('a.id,a.member_id,a.real_name,a.rank,b.mobile,count(c.id) as total')
->where('c.receive_member_id = b.id')->group('a.id')
->order('total desc')
->limit($page->firstRow, $page->listRows)
->select();

效果一样,join里面也可以不用带 on a.xx=b.xxx ,查询条件可以全部放到where里面

分析三

$res = M('member_attest')
->table('__MEMBER_ATTEST__ a,__MEMBER__ b')
->where('a.member_id = b.id')
->select();
$res = M('member_attest a')
->join('__MEMBER__ b')
->where('a.member_id = b.id')
->select();
$res = M('member_attest a')
->join('__MEMBER__ b ON a.member_id = b.id')
->select();

这三个都可以正常使用

thinkphp 3.2 多表查询 group的更多相关文章

  1. mysql 数据操作 单表查询 group by 分组 目录

    mysql 数据操作 单表查询 group by 介绍 mysql 数据操作 单表查询 group by 聚合函数 mysql 数据操作 单表查询 group by 聚合函数 没有group by情况 ...

  2. mysql 数据操作 单表查询 group by 介绍

    group by 是在where 之后运行 在写单表查询语法的时候 应该把group by 写在 where 之后 执行顺序 1.先找到表 from 库.表名 2.按照where 约束条件 过滤你想要 ...

  3. mysql 数据操作 单表查询 group by 注意

    GROUP BY 单独使用GROUP BY关键字分组 SELECT post FROM employee GROUP BY post; 注意:我们按照post字段分组,那么select查询的字段只能是 ...

  4. mysql 数据操作 单表查询 group by 练习

    小练习: 1. 查询岗位名以及岗位包含的所有员工名字 mysql> select post,group_concat(name) from employee group by post ; +- ...

  5. mysql 数据操作 单表查询 group by 聚合函数

    强调: 如果我们用unique的字段作为分组的依据,则每一条记录自成一组,这种分组没有意义 多条记录之间的某个字段值相同,该字段通常用来作为分组的依据 如果按照每个字段都是唯一的进行分组,意味着按照这 ...

  6. mysql 数据操作 单表查询 group by group_concat() 函数

    # group_concat() 和concat() 一样拼接字符串 用在分组里 需求:查看每个职位都有哪些员工名字 把所有员工成员的名字都列出来 把每个职位里的员工姓名列出来 mysql> s ...

  7. mysql 数据操作 单表查询 group by 聚合函数 没有group by情况下

    聚合函数只能用在组里使用 #没有group by 则默认算作一组 取出所有员工的最高工资 mysql> select max(salary) from employee; +---------- ...

  8. thinkphp中如何是实现多表查询

    多表查询经常使用到,但如何在thinkphp中实现多表查询呢,其实有三种方法. 1 2 3 4 5 6 7 8 9 10 11 12 // 1.原生查询示例: $Model = new Model() ...

  9. mysql 数据操作 单表查询 目录

    mysql 数据操作 单表查询 mysql 数据操作 单表查询 简单查询 避免重复DISTINCT mysql 数据操作 单表查询 通过四则运算查询 mysql 数据操作 单表查询 concat()函 ...

随机推荐

  1. 解压报错gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now的解决方法

    在部署tomcat的环境搞JDK的时候出现这个问题.分享一下. 解压命令:tar -zvxf memcached-1.4.34.tar.gz 遇到了一个问题, gzip: stdin: not in ...

  2. Git CMD连接,管理(remote,add,commit,push)github repository

    git initmd testcd testgit statusgit add test  //git add test/a.txtgit status git remote add origin g ...

  3. python - hadoop,mapreduce demo

    Hadoop,mapreduce 介绍 59888745@qq.com 大数据工程师是在Linux系统下搭建Hadoop生态系统(cloudera是最大的输出者类似于Linux的红帽), 把用户的交易 ...

  4. myeclipse之SSH整合图文详解

    首先搭建开发环境 打开MyEclipse,新建一个web project ,然后右击项目执行如下步骤: 开启服务器无错误即搭建成功,整合后项目目录: 另附上SSH所必须的开发包:

  5. Android RecyclerView网格布局

    一个简单的网格布局activity_main.xml <?xml version="1.0" encoding="utf-8"?> <andr ...

  6. RDD、DataFrame和DataSet

    简述 RDD.DataFrame和DataSet是容易产生混淆的概念,必须对其相互之间对比,才可以知道其中异同:DataFrame多了数据的结构信息,即schema.RDD是分布式的 Java对象的集 ...

  7. SQL 增删改查

    create table [表名]([自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,[字段1] nVarChar(50) default \'默认值\' null , ...

  8. unix的sed 用法介绍

    sed是一个非交互性性文本编辑器,它编辑文件或标准输入导出的文件拷贝.标准输入可能是来自键盘.文件重定向.字符串或变量,或者是一个管道文件.sed可以随意编辑小或大的文件,有许多sed命令用来编辑.删 ...

  9. drupal 精彩文章

    1.如何快速查找Drupal表单的Form ID?http://www.drupalla.com/node/2306

  10. python将dict中的unicode打印成中文

    import json a = {u'content': {u'address_detail': {u'province': u'\u5409\u6797\u7701', u'city': u'\u9 ...