...

View Full Version : Row Counting Question



Ted Varnson
09-09-2004, 05:20 PM
I have a table set up for class registrations. All the classes registered are put into that table. Is there a way I can have asp count the number of rows with Productive Organic Gardening, and the other class names to display the number registered, or am I goingto have to redo my whole scheme and have separate tables for each class?

Roy Sinclair
09-09-2004, 05:33 PM
The "Sum" function in SQL should be able to get you what you want.


Edit--- I said Sum but as others have pointed out, Count is the right function.

oracleguy
09-09-2004, 06:57 PM
And it sounds like you might need to use Count() as well.

Roelf
09-09-2004, 07:29 PM
like:


SELECT COUNT(*) FROM yourtablename GROUP BY yourcolumnamewhichholdstheclassname

Ted Varnson
09-09-2004, 10:04 PM
So how would I have that display the number as in

Class name - 3 registrations

oracleguy
09-09-2004, 10:07 PM
SELECT COUNT(*), yourcolumnamewhichholdstheclassname FROM yourtablename GROUP BY yourcolumnamewhichholdstheclassname

Should return the count and the class name then.

Ted Varnson
09-10-2004, 09:30 PM
SELECT COUNT(*), yourcolumnamewhichholdstheclassname FROM yourtablename GROUP BY yourcolumnamewhichholdstheclassname

Should return the count and the class name then.

that didn't work, but when I changed it to "SELECT COUNT(*) as classid FROM informal_classes GROUP BY classid" it did, however, I still can't get it to display the actual class name, which is in another column (called classname)

Roy Sinclair
09-10-2004, 09:43 PM
Try:



SELECT COUNT(distinct classid),classname FROM informal_classes GROUP BY classname

Ted Varnson
09-13-2004, 07:11 PM
Try:



SELECT COUNT(distinct classid),classname FROM informal_classes GROUP BY classname


I get "Syntax error (missing operator) in query expression 'COUNT(distinct classid)'."

Roelf
09-13-2004, 08:09 PM
select count(*) as registrations, classname from informal_classes group by classname

Roy Sinclair
09-13-2004, 08:35 PM
What SQL engine?

Ted Varnson
09-13-2004, 08:48 PM
select count(*) as registrations, classname from informal_classes group by classname


Excellent, that works. Thanks a lot everyone. this forum is the best place I've ever visited.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum