2013-07-08 95 views
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) 
+0

哪個DBMS是這個呢? –

回答

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