Jump to content

Archived

This topic is now archived and is closed to further replies.

rockonxox

Counting rows based on a column value?

Recommended Posts

The site I am using this for is a secret santa database for a web group I'm a part of. Everything works fine, but I'm noticing that many members have more "gift items" than others.

 

The table for gifts that have been sent (which I am wanting to count), records many presents for each individual, which is why I need to count the rows based on the column of "hfname". So in short, I want to count the rows, using the column hfname, and group them based on if the name shows up in 0, 1-3, 5-10, or 10+ rows.

 

I want to set up the gift analysis like so:

Members with no gifts

(insert php to count hfname values returning 0 rows)

 

Members with 1-3 gifts

(insert php to count hfname values returning 1-3 rows)

 

Members with 5-10 gifts

(insert php to count hfname values returning 5-10 rows)

 

Members with over 10 gifts

(insert php to count hfname values returning >10 rows)

 

---------------

 

This is really the first site I've done using databases, so it's more a learning tool than anything of real use, at least not unless it's the holidays =)

Share this post


Link to post
Share on other sites

Not sure whether this is what you want

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM yourtable WHERE hfname='0' [!--sql2--][/div][!--sql3--]

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM yourtable WHERE hfname BETWEEN '1' AND '3' [!--sql2--][/div][!--sql3--]

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM yourtable WHERE hfname>10 [!--sql2--][/div][!--sql3--]

Share this post


Link to post
Share on other sites

Not sure if that will work. Hfname is just a column fieldname... I want to be able to get results like this:

 

Member has 0 presents

Kelly

Alia

Candymara

 

Member has 1-3 presents

Tigerlily

Dana

KirstinVP

 

Members has 5-10 presents

JillianVP

 

Member has 10+ presents

None

 

 

So I'd need to count rows based on how many times a value occurs in the hfname column...

Share this post


Link to post
Share on other sites

×

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.