php - SQL - Count how many itmes in a GROUP also using SUM -


i'm using pdo (still learning) , have current sql query. works perfectly, merging duplicate entries , adding value. there way see how many duplicate entries there were?

$sql = "select col1, sum(col2) table date > :fromdate , date < :enddate group col1"; 

my table looks this

col1     col2  -----  ------ abc       2 aba       3 add       1 aed       3 abc       2 aba       3 add       1 aed       3 aed       0 

at moment, after loop through, result looks this

col1    col2     ----    ----     abc       4 aba       6 add       2 aed       6 

but i'd value of how many times occured in db before grouped end with

col1    col2    times appeared ----    ----    -------------- abc       4           2 aba       6           2 add       2           2 aed       6           3 

use count() that. counts records in group if used group by

select col1, sum(col2), count(*) 'times appeared' table  date > :fromdate , date < :enddate  group col1" 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -