CI 框架多表关联查询
public function getCollectData($limit, $page, $search_user, $search_phone, $orderfield, $ordertype)
{
$this->db->select('a.id,a.mobile,a.is_del,a.register_ip,a.add_time,
b.parent_id as master_id,
ifnull(inv.award,0) as invite_moneys,
ifnull(bro.price,0) as brokerage_moneys,
ifnull(sha.read_price,0) as share_moneys,
ifnull(sha.counts,0) as share_counts,
(ifnull(inv.award,0)+ifnull(bro.price,0)+ifnull(sha.read_price,0)) as total_moneys');
$this->db->from(self::$table_name . ' a');
$this->db->join('ws_invitation b', 'a.id = b.user_id', 'left');
$this->db->join('(SELECT sum(award) as award,user_id FROM ws_invitation_log GROUP BY user_id) as inv', 'a.id = inv.user_id', 'left');
$this->db->join('(SELECT sum(price) as price,prentice_id FROM ws_brokerage_log GROUP BY user_id) as bro', 'a.id = bro.prentice_id', 'left');
$this->db->join('(SELECT sum(read_number*read_price) as read_price,count(id) as counts,
user_id FROM ws_share_record GROUP BY user_id) as sha', 'a.id = sha.user_id', 'left');
$this->db->where(['is_channel' => 0]); if ($search_user) {
$this->db->where(['a.id' => $search_user]);
}
if ($search_phone) {
$this->db->like('a.mobile', $search_phone, 'both');
}
if ($orderfield && $ordertype) {
$this->db->order_by($orderfield . ' ' . $ordertype);
} else {
$this->db->order_by('a.id DESC');
}
$this->db->group_by('a.id');
$this->db->limit($limit, $limit * ($page - 1));
return $this->db->get()->result_array();
}
CI 框架多表关联查询的更多相关文章
- CI 多表关联查询
方法一:$this->db->query("sql 语句"); 直接写sql语句 方法二: #多表关联查询 $data=$this->db->fr ...
- RDIFramework.NET 中多表关联查询分页实例
RDIFramework.NET 中多表关联查询分页实例 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,给用户和开发者最佳的.Net框架部署方案.该框架以SOA范式作为 ...
- 【SQL】在SQL Server中多表关联查询问题
好久没有写SQL语句的多表连接查询,总在用框架进行持久化操作.今天写了一个多表关联查询,想根据两个字段唯一确定一条数据 失败的案例如下: SELECT cyb.id,ad.name FROM [Gen ...
- Spring Boot入门系列(十七)整合Mybatis,创建自定义mapper 实现多表关联查询!
之前讲了Springboot整合Mybatis,介绍了如何自动生成pojo实体类.mapper类和对应的mapper.xml 文件,并实现最基本的增删改查功能.mybatis 插件自动生成的mappe ...
- MSSQL N张表关联查询
declare @newTime varchar(50); declare @lasetTime varchar(50); set @newTime= getdate(); set @lasetTim ...
- 图解SQL多表关联查询
图解SQL多表关联查询 网上看了篇文章关于多表连接的,感觉很好,记录下来,以便日后自己学习 内连接 左连接 右连接 全外连接 1. 查两表关联列相等的数据 ...
- Oracle 数据库(oracle Database)Select 多表关联查询方式
Oracle数据库中Select语句语法及介绍 SELECT [ ALL | DISTINCT ] <字段表达式1[,<字段表达式2[,…] FROM <表名1>,<表名 ...
- ORACLE数据库多表关联查询效率问题解决方案
最近在做项目中遇到多表关联查询排序的效率问题(5张以上40W+数据的表),查询一次大概要20多秒,经过一番苦思冥想,处理方案如下: 1.软件设计初期,需要一对一关联的表应该设计在一张大表里,这样虽然字 ...
- mongodb操作之使用javaScript实现多表关联查询
一.数据控制 mongodb操作数据量控制,千万控制好,不要因为操作的数据量过多而导致失败. 演示一下发生此类错误的错误提示:
随机推荐
- AcWing 1022. 宠物小精灵之收服 二维费用背包
#include<iostream> using namespace std ; ; int f[N][N]; int V1,V2,n; int main() { cin>>V ...
- Linux oracle中文乱码的问题解决
乱码问题的根源是字符集的修改 1.查看linux的默认语言 2.查看客户端的语言编码设置 配置文件中的配置: cat ~/.bash_profile 注意修改配置信息: export PATHexp ...
- TNS-12545: Connect failed because target host or object does not exist
问题描述 $ lsnrctl startLSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2017 09:53:42Copyri ...
- linux命令 mv
后缀--backup=<备份模式>:若需覆盖文件,则覆盖前先行备份: -b:当文件存在时,覆盖前,为其创建一个备份: -f:若目标文件或目录与现有的文件或目录重复,则直接覆盖现有的文件或目 ...
- Oracle允许IP访问配置
http://www.linuxidc.com/Linux/2014-10/108650.htm 1.oracle服务器下/opt/app/oracle/product/11.2.0/network/ ...
- Oracle 12.2.0.1 Installation Fails With "PRVG-0449"
Mac 电脑虚拟机 Parallels 中进行Oracle 12.2.0.1 数据库软件安装时,预环境检查过程中,提示堆栈大小限制[失败],即使修复问题依然如故. Oracle 12.2.0.1 In ...
- java多线程技术
如何实现线程 首先实现线程的两个方法:1.继承thread:2.实现接口Runnable类: 这边我就说一下第二种,因此第二种在开发中使用的比较多一些,能避免继承还是少避免继承. RunnableDe ...
- python 3.8 下安装 tensorflow 1.14
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.14.0-py3-none-a ...
- 【转载】 __declspec(dllexport) 和__declspec(dllimport)
转自:http://www.cppblog.com/Dutyboy/archive/2010/11/15/133699.html __declspec(dllexport) __declspec( ...
- AcWing 开平方 浮点数二分
#include<iostream> using namespace std; int main() { double x; cin>>x; ,r=x; ) //for(int ...