apache
apache

Reputation: 55

to get the TOTAL of 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 

I solve my problem with your help only

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

Upvotes: 1

Views: 64

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269633

If you need only the total of count, then remove the group by:

SELECT COUNT(  `ftm_content_type` ) AS count
FROM ftm_points

If you need the total on the same line, then join it back in:

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 

And finally, if you want the total on a separate line, then use rollup:

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

Upvotes: 1

Related Questions