Click to See Complete Forum and Search --> : Select count of type by person


dz_boy
01-02-2010, 06:29 PM
I have a database table that is a list of items. It has columns for id, type_id, date, staff_id, memo, etc. I'm trying to select the number of items (i.e. using the count() function) of each type per person. So the output table would be like:


Name: | Count of Type 1: | Count of Type 2 | .......
--------------------------------------------------------------------
Chris | 3 | 2 |
John | 2 | 1 |


Any ideas? I think it's a matter of counting the items based on type_id and then grouping them by staff_id, but I can't seem to get it.

Any help is appreciated! Thanks.

like_php
01-03-2010, 04:14 AM
its depends of what u want and use group by as u need
for example


//change * to what you want count to
$sql = '
select name, count(*) as countNumber
from table
group by itemId