tags:

views:

15

answers:

3

hypothetic tables

user_id | hits

Can I get MySQL to return the total hits of a Select query? I know i could add them together with php or similar, just wondering if there is a pure MySQL way?

+2  A: 
 Total hits per user

 SELECT userId, Sum(Hits)
 FROM Table
 GROUP by userId

 OR 

 Total hits

 SELECT Sum(Hits)
 FROM Table
Michael Pakhantsov
+1  A: 
select sum(hits) from ...
ar
+1  A: 

Depending on the specific SQL query you're using you could either SUM a column or potentially use the 'WITH ROLLUP' GROUP modifier if you require a query-wide total.

middaparka