Not sure how to get it to sort and count

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ee99ee
Forum Newbie
Posts: 9
Joined: Mon Mar 03, 2003 6:45 pm
Location: TN, USA
Contact:

Not sure how to get it to sort and count

Post by ee99ee »

Okay I've got a table that has 3 feilds: id, size, style. Right now, I have a SQL statement pulling the data from the database, and pushing it out to a webpage (using PHP of course). It just pulls everything from the table with that info, and sorts it by id. Here's an example:

Code: Select all

id    size   style
168   40S    TL
169   40S    OL
170   40S    ODB
171   40S    ODB
172   40S    ODB
173   40R    N
174   40R    N
Now, what I want it to do is that that information, and make a new table showing how much of each size and style are in the table. Example using above info:

Code: Select all

num   size   style
1 40S TL
1 40S OL
3 40S ODB
2 40R N

I'm not really sure how I should go about trying to get it to do that, so if you've got any suggestions on how, I'd love to hear them.

Thanks!!!

-ee99ee
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Code: Select all

SELECT COUNT(id), size, style FROM table GROUP BY size
Or something like that.

btw, hi (newbienetwork from #php)
ee99ee
Forum Newbie
Posts: 9
Joined: Mon Mar 03, 2003 6:45 pm
Location: TN, USA
Contact:

Post by ee99ee »

woooo!!! thank you!!!!

btw, howdy! (eeiiee from #php of course)...


-ee99ee
Post Reply