Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting records 1

Status
Not open for further replies.

soklear

IS-IT--Management
Jan 13, 2004
38
US
If I have the following table in a database:

ROW1 ROW2 ROW3
1 a x
2 b y
3 c z
4 a x
5 b c
6 a g

and want to perform a select querie where the querie returns the total number of rows where a value exists:

So, the return would be:

Name (From row 2) Count of times value is in Row2
a 3
b 2
c 1

How would I do this?

I have tried a count, sum, etc but cannot figure out how to select everything from row2 and then categorize the values and count them at the same time.

Any help with this will be appreciated.
Also - can anyone give me the name of a book that I can buy that I can use as both a GOOD reference and teach myself SQL at the same time. The 'Teach yourself in x days' didnt seem to be enough information.

Thanks -

Bob
 
FIGURED IT OUT!!!! (Not that anyone cares)....


select TABLEA.row2, count(TABLEA.row2) as 'TOTAL'
group by row2;


:)

Bob
 
i care :)

----------------------------------------
There are 2 types of computer, the prototype and the obsolete!!
 
Thanks man (or woman)!

As an editorial, it seems like I try to make things to hard when programming in SQL. But, when I take a step back and actually look at the problem as a whole instead of pigeon-holing it to death with case and whatever else I can come up with and try the simplest expression - it works. or atleast in this case. Thanks for letting me share my epiphany.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top