码迷,mamicode.com
首页 > 数据库 > 详细

统计SQL

时间:2017-07-26 21:54:22      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:笔记

候选人列表

SELECT 

  (@rowNum := @rowNum + 1) AS rowNo,

  C.NUMBER,

  C.HEADIMG,

  C.NAME,

  C.SECTION,

  C.DECLARATION,

  C.INTRODUCTION,

  V.NAME VOTENAME,

  IFNULL(T.TICKET, 0) TICKET 

FROM

  TB_CANDIDATE C 

  LEFT JOIN 

    (SELECT 

      COUNT(*) TICKET,

      D.VOTE_ID,

      D.CANDIDATE 

    FROM

      TB_VOTE_DETAIL D 

    GROUP BY D.CANDIDATE,

      D.VOTE_ID) T 

    ON T.CANDIDATE = C.ID 

  LEFT JOIN TB_VOTE V 

    ON C.VOTE_ID = V.VOTE_ID,

  (SELECT 

    (@rowNum := 0)) b 

WHERE C.STATUS = ‘1‘ 

---------------------------

投票人情况

SELECT 

  (@rowNum := @rowNum + 1) AS rowNo,

  C.NAME,

  D.OPENID,

  P.PHONE,

  COUNT(*) AMOUNT

FROM

  TB_VOTE_DETAIL D 

  LEFT JOIN TB_OPENID_PHONE P 

    ON D.OPENID = P.OPENID 

    LEFT JOIN TB_CANDIDATE C 

    ON D.CANDIDATE=C.ID,

    (SELECT 

    (@rowNum := 0)) b 

WHERE D.CANDIDATE = ‘1‘ 

GROUP BY D.OPENID

ORDER BY AMOUNT DESC


本文出自 “Java乐园” 博客,请务必保留此出处http://hebinteng.blog.51cto.com/7967512/1951183

统计SQL

标签:笔记

原文地址:http://hebinteng.blog.51cto.com/7967512/1951183

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!