Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Got me stumped...

Author  Topic 

JLGoldenEagle
Starting Member

1 Post

Posted - 2009-07-08 : 14:45:35
I am new to SQL and find it very tricky. In the following, the GID is unique but the CID is not. How do you find how many GID's are on each and every CID?
Example Table:

CID GID
1 100
2 200
1 132
1 112
2 210
3 300
3 331




Every where I go, There I am!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 14:47:03
[code]SELECT CID,COUNT(GID) AS GIDCount
FROM YourTable
GROUP BY CID
[/code]
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-08 : 15:46:44
quote:
Originally posted by JLGoldenEagle
How do you find how many GID's are on each and every CID?



That would be 1

How do you find how many GID's there are for each unique CID?

See above

COUNT(*) or COUNT(GID)?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-09 : 10:14:31
quote:
Originally posted by X002548

quote:
Originally posted by JLGoldenEagle
How do you find how many GID's are on each and every CID?



That would be 1

How do you find how many GID's there are for each unique CID?

See above

COUNT(*) or COUNT(GID)?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam






how would that be 1?
see sample data for ex for CID=1 it will be 3 (GID=100,132,112)
Go to Top of Page
   

- Advertisement -