获得总计数

时间:2013-07-08 17:44:51

标签: php sql count

SELECT * , COUNT(  `ftm_content_type` ) AS count,
       max(tot.totcount) as totcount
FROM ftm_points join
     (select count(*) as totcount from ftm_points) tot
GROUP BY ftm_content_type 

我只在你的帮助下解决了我的问题

FTM_CONTENT_TYPE = 4 3 2 1
COUNT            = 3 2 3 2   =  TOTAL OF COUNT = 10(I need this result) 

1 个答案:

答案 0 :(得分:1)

如果您只需要总计数,请删除group by

SELECT COUNT(  `ftm_content_type` ) AS count
FROM ftm_points

如果您需要同一行的总数,请将其重新加入:

SELECT * ,
       COUNT(  `ftm_content_type` ) AS count,
       max(tot.totcount) as totcount
FROM ftm_points join
     (select count(*) as totcount from ftm_points) tot
GROUP BY ftm_content_type 

最后,如果您想要单独一行的总数,请使用rollup

SELECT * ,
       COUNT(  `ftm_content_type` ) AS count
FROM ftm_points 
GROUP BY ftm_content_type with rollup