历史SQL语句之一
注释:查询该课程表下,所有的课程以及课程观看的人数统计
SELECT ml.`name` as lessonName,ml.category,ml.deleted,ml.teacherName,
ml.id,ml.liveId,ml.selected,mlc.channelId,p.viewNums,count(*) as totalNum
from mlk_live_channel AS ml
LEFT JOIN mlk_lesson_channel AS mlc ON mlc.lessonId = ml.id
LEFT JOIN mlk_live_channel AS mcl ON mcl.id = mlc.channelId
LEFT JOIN
(SELECT mpr.liveId,mpr.memberId,COUNT(mpr.liveId) as viewNums FROM mlk_payment_record AS mpr
WHERE mpr.payType = 3 AND mpr.notify = 1 GROUP BY mpr.liveId) AS p
ON p.liveId = mcl.liveId
WHERE ml.deleted = 0 AND ml.category = 1
GROUP BY ml.id
ORDER BY ml.create_time
$connection = $this->db;
$sql = "SELECT ml.name as lessonName,ml.category,ml.deleted,ml.teacherName,ml.banner,
ml.id,ml.liveId,ml.selected,mlc.channelId,p.viewNums,count(mlc.lessonId) as totalLesson
from mlk_live_channel AS ml
LEFT JOIN mlk_lesson_channel AS mlc ON mlc.lessonId = ml.id
LEFT JOIN mlk_live_channel AS mcl ON mcl.id = mlc.channelId
LEFT JOIN
(SELECT mpr.liveId,mpr.memberId,COUNT(mpr.liveId) as viewNums FROM mlk_payment_record AS mpr
WHERE mpr.payType = 3 AND mpr.notify = 1 GROUP BY mpr.liveId) AS p
ON p.liveId = mcl.liveId
WHERE ml.deleted = 0 AND ml.category = 1
GROUP BY ml.id
ORDER BY ml.create_time";
$totals = $connection->fetchAll($sql);
$this->view->setVar('channles', $totals);
SELECT ml.`name` as lessonName,ml.category,ml.deleted,ml.teacherName,mlc.channelId,ml.liveId,ml.banner,
ml.id,ml.selected,mlc.channelId,SUM(p.viewNums) as totalViews,COUNT(mlc.lessonId) AS totalLesson
from mlk_live_channel AS ml
LEFT JOIN mlk_lesson_channel AS mlc ON mlc.lessonId = ml.id
LEFT JOIN
(SELECT mlc.id,mlc.liveid,count(DISTINCT mpr.memberId) as viewNums
FROM mlk_live_channel AS mlc
LEFT JOIN mlk_payment_record AS mpr ON mpr.liveId = mlc.liveId
WHERE mlc.deleted = 0 and mlc.category = 2 AND mpr.payType = 4
GROUP BY mlc.liveId ) AS p
ON p.id = mlc.channelId
WHERE ml.deleted = 0 AND ml.category = 1
GROUP BY ml.id
HAVING SUM(p.viewNums)>0
历史SQL语句之一的更多相关文章
- pl/sql developer 快捷操作: 显示不可见字符 显示历史sql语句 拷贝整个sql窗口的语句至新的sql窗口
pl/sql developer 快捷操作: 显示不可见字符 显示历史sql语句 拷贝整个sql窗口的语句至新的sql窗口 显示不可见字符:可以把空格.回车显示出来: 显示历史sql语句:ctrl+e ...
- 如何查看 SQL Server 执行的历史 SQL 语句记录?
SELECT st.text as sql_statement, qs.creation_time as plan_last_compiled, qs.last_execution_time as p ...
- 通过SID查找历史执行的SQL语句
这次某系统发生严重的阻塞,但是去查顶级会话,发现已经没有该对应的sql_id了,于是我们只用通过 v$active_session_history 视图来寻找.下面是查找的过程: 1.查找顶层ASH历 ...
- 个人永久性免费-Excel催化剂功能第21波-Excel与Sqlserver零门槛交互-执行SQL语句篇
在前两波中,已完成了Excel与Sqlserver的查询和上传功能,但难免许多临时的或更深入地操作数据库需要用Sql语句来操作,对一般用户电脑里,不可能有条件轻易安装一个数据库客户端软件,就算安装了对 ...
- 巧用DISPLAY_AWR函数与dba_hist_sqlstat结合查询SQL语句在指定节点指定时间范围内的历史执行计划
1.问题 通过调用dbms_xplan包中DISPLAY_AWR函数(DBMS_XPLAN.DISPLAY_AWR)可以从AWR数据中查看到SQL语句的历史执行计划,但是,DISPLAY ...
- Mysql 常用 SQL 语句集锦
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- SQL语句优化(转载)
一.操作符优化 1.IN 操作符 用IN写出来的SQL的优点是比较容易写及清晰易懂,这比较适合现代软件开发的风格.但是用IN的SQL性能总是比较低的,从Oracle执行的步骤来分析用IN的SQL与不用 ...
- 如何用ORM支持SQL语句的CASE WHEN?
OQL如何支持CASE WHEN? 今天,一个朋友问我,OQL可否支持CASE WHEN语句?他给的示例SQL如下: then '启用' else '停用' from tb_User OQL是SOD框 ...
- Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
随机推荐
- JeeSite4.x 搭建并部署到服务器
1.下载地址:https://gitee.com/thinkgem/jeesite4 2.文档地址:http://jeesite4.mydoc.io/?t=267354 2.1一定要看,都很清晰,没废 ...
- 在VS中安装nuget离线包nupkg文件
1.下载 nupkg文件 2.打开VS,工具,选项,如下图,复制右侧圈圈地址,把下载文件复制丢进去 3.管理当前解决方案的nuget包 n 4.左侧选择你下载的包名,在右侧选择需要安装在哪一层项目,点 ...
- Android LinearLayout 渐变背景
更多 参考 Drawable Resources | Android Developers main_header.xml: <?xml version="1.0" enc ...
- 51nod 1081 子段求和(线段树 | 树状数组 | 前缀和)
题目链接:子段求和 题意:n个数字序列,m次询问,每次询问从第p个开始L长度序列的子段和为多少. 题解:线段树区间求和 | 树状数组区间求和 线段树: #include <cstdio> ...
- hdu 2594 Simpsons’ Hidden Talents(扩展kmp)
Problem Description Homer: Marge, I just figured out a way to discover some of the talents we weren’ ...
- js 时间日期格式转换
Date.prototype.Format = function(formatStr) { var str = formatStr; var Week = ['日', '一', '二', '三', ' ...
- CF1101
D:题意:树上每个顶点有个权值,求最长链,满足链上gcd > 1 解:对每个质数建虚树,每个点只会拆成log个点,所以是log2的. #include <bits/stdc++.h> ...
- Httpclient超时timeout设置
一:连接超时:connectionTimeout 1:指的是连接一个url的连接等待时间. 二:读取数据超时:soTimeout 1:指的是连接上一个url,获取response的返回等待时间. Fo ...
- jquery的checked以及disabled
下面只提到checked,其实disabled在jquery里的用法和checked是一模一样的 下边两种写法没有任何区别 只是少了些代码而已... ------------------------- ...
- keepalived+LVS实现网站负载均衡和HA
如上图所示,102和103是内网nginx服务器,100和101是边界LB,clinet是1,这个实验是为了实现在LB上虚拟出一个VIP,client通过访问该VIP,来动态负载到两台内网nginx服 ...