历史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

 

上一篇:SocketLog


下一篇:【错误解决】[Maven]使用Maven配置Jstl出现异常:The absolute uri: http://java.sun.com/jsp/jstl/core cannot...