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 2008 Forums
 Analysis Server and Reporting Services (2008)
 using count

Author  Topic 

DanielS
Starting Member

32 Posts

Posted - 2013-11-28 : 22:57:29
Hello all, I am looking to create a column of data which only counts by like cells from two other fields.

My data is ID and Type, I'm looking ot produce the Count:
ID Type Count
A X 1
A X 1
B X 1
B X 1
A Y 2
A Y 2
B Y 2
B Z 3

I couldn't do this via a standard COUNT or via a ROW() PARTITION. Is the best way to concateante ID and Type?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-28 : 23:03:51
wont this be enough?

SELECT ID,Type, DENSE_RANK() OVER (ORDER BY Type) AS [Count]
FROM Table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

DanielS
Starting Member

32 Posts

Posted - 2013-11-28 : 23:44:06
That's it, thanks Visakh16.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-29 : 00:07:44
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -