Jump to content

Simple "COUNT" help


Crooked

Recommended Posts

Hey guys,

 

I'm currently trying to count how many of the same kind of "id" there is in a certain table and then it should print out the rows by either ASC or DESC starting or ending on the highest/lowest.

 

 

To understand it better:

 

I have a table where i have 2 different types of rows ( cake / cofee )

 

In the "cake" row it could possibly be something like -

Cake - row

1

1

1

1

1

2

2

 

i want help with how i can do a COUNT on how many number 1 there is and how many number 2 there is and etc to about 5, and then have em print out the cakes name from the highest bought one to the lowest one.

 

 

Thanks :)

Link to comment
Share on other sites

To get counts per group you need to do a GROUP BY on the column that has the type ID's.  I have no idea what your table structure looks like, but something like this:

 


SELECT COUNT(*) as countof, rowtype FROM cake GROUP BY rowtype ORDER BY countof DESC LIMIT 5

Link to comment
Share on other sites

here is a image of what i was trying to get to:

 

countproblem.jpg

 

and forget about the cofee table.

 

So simple put i wanted to make a hit-list or top-list of a sort because i havn't gotten around to get familier with the count that much.

 

 

(FYI this is a example i quickly threw together, i left the original files on my laptop which is at home)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.