mysql - SUM of Column where Multiple Rows Have Same Value -
i trying sum of single column rows share similar data. example, given following data:
|ppid | cid | count | namespace| |-----|-------|-------|----------| |586 | 18281 | 1 | lab | |587 | 18269 | 1 | lab | |588 | 18281 | 1 | lab | |589 | 17823 | 1 | ipb | |590 | 18281 | 1 | lab | |591 | 18256 | 1 | lab | |592 | 18256 | 1 | lab | |593 | 18269 | 1 | ipb | |-----|-------|-------|----------| i'm hoping get:
|ppid | cid | count | namespace| |-----|-------|-------|----------| |586 | 18281 | 3 | lab | |587 | 18269 | 1 | lab | |589 | 17823 | 1 | ipb | |591 | 18256 | 2 | lab | |593 | 18269 | 1 | ipb | |-----|-------|-------|----------| i've pieced couple of different things , come `
select * popularpages cid in (select cid popularpages group cid having count(cid) > 1) order cid, namespace which list out each of rows without counting sum of count column. appreciated.
is want ?
select min(ppid) ppid, cid, sum(`count`) count, namespace popularpages group cid having count > 1;
Comments
Post a Comment