1
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) 
4

1 回答 1

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
于 2013-07-08T18:10:02.010 回答