Forum Moderators: open

Message Too Old, No Replies

counting frequency in database

Anybody help?

         

phill2000star

3:09 pm on May 24, 2007 (gmt 0)

10+ Year Member



Hi all.

I'm new to MySQL and have been working on a project.

I currently have the following data in a database.

id ¦ productID ¦ custID ¦ Item
-------------------------------------------------------
1 ¦ XTVI00850 ¦ 30013 ¦ Stage 7 - Gone Wild / The Fiddle
2 ¦ XTVI00956 ¦ 30023 ¦ Stu G Vs. Satsta - Like A Prayer
3 ¦ XTVI00690 ¦ 30011 ¦ Di Scala & Crellin - Touch My Body
4 ¦ XTVI00618 ¦ 30013 ¦ Neo Cortex - Elements
5 ¦ XTVI00618 ¦ 30001 ¦ Neo Cortex - Elements
-------------------------------------------------------

Basically this is a list of what "out of stock" people are wanting from an online store. If the item is out of stock it puts their entry into the above database recording their interest.

What I want to do is list all the items that users are wanting in the following fashion.

id ¦ productID ¦ QTY ¦ Item
-------------------------------------------------------
1 ¦ XTVI00618 ¦ 2 ¦ Neo Cortex - Elements
2 ¦ XTVI00690 ¦ 1 ¦ Di Scala & Crellin - Touch My Body
3 ¦ XTVI00850 ¦ 1 ¦ Stage 7 - Gone Wild / The Fiddle
4 ¦ XTVI00956 ¦ 1 ¦ Stu G Vs. Satsta - Like A Prayer
-------------------------------------------------------

I have hit a brick wall trying to figure out the SQL statement for this and I think it is beyond my comprehension!

Can anyone help?

LifeinAsia

3:17 pm on May 24, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



SELECT productID, COUNT(*) AS QTY, Item
FROM YourTable
GROUP BY productID, Item