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
 counting rows

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-02-15 : 15:26:03
is there a way to count the sort of a query and still get the values in the query

columns1, column2, column3 are the same for 5 rows so give the values of each column and then count =5

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 15:31:25
Use a subquery

SELECT t1.Col1, t1.Col2, t1.Col3, (SELECT COUNT(*) FROM Table1 AS t2 ON t2.Col1 = t1.Col1 AND t2.Col2 = t1.Col2 AND t2.Col3 = t1.Col3)
FROM Table1 AS t1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-02-15 : 15:40:27
it doesnt like the ON
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-15 : 15:42:56
Are you simply asking for

select col1,col2,col3, count(*)
from yourtable
group by col1, col2, col3

... or something different? An example would help.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-02-15 : 16:23:57
what peso sent worked justed need to change the on to where

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-15 : 16:45:25
quote:
Originally posted by tpiazza55

what peso sent worked justed need to change the on to where





So you aren't using SQL Server? If not, you need to tell us that when you post.

Tara Kizer
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-02-15 : 16:56:13
no im using sql2005 just didnt like that on statement
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-15 : 17:22:11
[code]
SELECT t1.Col1, t1.Col2, t1.Col3, (SELECT COUNT(*) FROM Table1 AS t2 ON WHERE t2.Col1 = t1.Col1 AND t2.Col2 = t1.Col2 AND t2.Col3 = t1.Col3)
FROM Table1 AS t1
[/code]


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 17:39:51
My bad. Old habit writing ON..


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -