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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 count value

Author  Topic 

hai
Yak Posting Veteran

84 Posts

Posted - 2007-06-06 : 09:28:51
hi all,

I have the following table,

c1,c2
1, 3
1, 4
1, 5
2, 2
2, 3
2, 0
3, 2
3, 2
3, 5

I want to select if the column c1 is the same, group c1 but count c2
eg
1, 3
2, 3
3, 2

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-06 : 09:30:48
[code]
select c1, count(distinct c2)
from tbl
group by c1
[/code]


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-06 : 09:31:26
Your expected output is wrong.

it should be
1,3
2,3
3,3

EDIT: Okay, DISTINCT, that makes sense.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-06 : 10:25:15
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-06-06 : 15:00:20
Madhi, are you talking to harsh or hai?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-07 : 07:10:11
quote:
Originally posted by DonAtWork

Madhi, are you talking to harsh or hai?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Guess

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-07 : 07:16:52
me ?


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-07 : 09:53:10
quote:
Originally posted by khtan

me ?


KH



Guess again

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -