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 2005 Forums
 Transact-SQL (2005)
 Query problem -- can help?

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2010-02-21 : 10:39:40
My table and row as follows,
cout
TID | RID | Cout | Seq | Stat | Remk
-------------------------------------------------------------------
_d091100008882 _r00000007 KL 1 A NULL
_d091100008882 _r00000007 JB 2 A NULL
_d091100008882 _r00000007 SG 3 A NULL
_d091100008930 _r00000024 JB 1 A NULL
_d091100008930 _r00000024 KL 2 A NULL
_d091100008930 _r00000024 KLANG 3 A NULL
_d091100007971 _r00000007 KL 1 A NULL

i want my resultset as follow,
TID | NoOfTID | RID
----------------------------------------------------------------
_d091100008882 3 _r00000007
_d091100008930 3 _r00000024
_d091100007971 1 _r00000007

how to count(TID)?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-21 : 10:46:06
[code]SELECT TID,RID,COUNT(*) AS NoOfTID
FROM table
GROUP BY TID,RID
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2010-02-21 : 10:54:23
tq sir. my problem is not understand how to using group by
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-21 : 10:56:59
quote:
Originally posted by Delinda

tq sir. my problem is not understand how to using group by


sorry didnt get you
did you mean this is not what you want?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-02-21 : 14:58:11
quote:
Originally posted by visakh16

quote:
Originally posted by Delinda

tq sir. my problem is not understand how to using group by


sorry didnt get you
did you mean this is not what you want?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




No...I guess OP said he did not know how to use GROUP BY...but now he does.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-22 : 08:09:37
quote:
Originally posted by vijayisonly

quote:
Originally posted by visakh16

quote:
Originally posted by Delinda

tq sir. my problem is not understand how to using group by


sorry didnt get you
did you mean this is not what you want?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




No...I guess OP said he did not know how to use GROUP BY...but now he does.


Oh I see

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -