On Fri, 2009-02-27 at 13:21 -0500, Bastien Koert wrote:
> On Fri, Feb 27, 2009 at 11:17 AM, revDAVE <c...@hosting4days.com> wrote:
> 
> > Newbie question
> >
> > Hi folks,
> >
> > Currently, I have an inventory table that stores individual records for
> > each
> > single item in inventory - ( each item is on its own line because it has
> > serial numbers associated with it) like:
> >
> > fields:
> >
> > Item - ModelID - sn
> >
> >
> > item1 - 1 - sn xxx
> > item1 - 1 - sn xxx
> > item2 - 2 - sn xxx
> > item2 - 2 - sn xxx
> > item2 - 2 - sn xxx
> > item3 - 2 - sn xxx
> >
> > Goal: I would like to give a report page with total counts for current in
> > inventory like:
> >
> > COUNTS...
> > item1 = 2
> > item2 = 3
> > item3 = 1
> >
> > so I created a fool around query that gets a count for just ModelID = 1
> >
> > $query_count_model1 = "SELECT count(inventory_id) as thecount FROM
> > inventory
> > WHERE ModelID = 1";
> >
> > BUT: - the I'm sure there is some better way to get a count for *each* of
> > the ModelID that exist in any given time *all at once* in some kind of loop
> > or xxx???... I just don't know how do that...
> >
> > (newbie alert) - I would appreciate any ideas or URL links etc. - please
> > keep is simple for this newbie....
> >
> >
> >
> >
> > --
> > Thanks - RevDave
> > Cool @ hosting4days . com
> > [db-lists 09]
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> select modelId, count(*) as total from table group by modelId
> 
Don't do a count(*) if you can avoid it, as it's a lot slower than doing
a count on an individual field.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to