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.
Author |
Topic |
Cal88
Starting Member
3 Posts |
Posted - 2014-07-20 : 19:18:42
|
Hello, Hoping to get some help on how to create a hierarchy using SQL. I have a database with ID numbers that are duplicated based on customer preferences. For example, an ID number can fall into multiple categoriesID# 001 in section AID# 001 in section BID# 001 in section CThe same ID Number is in section A, B and C.The hierarchy is that A is at the top and C is at the bottom. So, if my ID number is in all 3 sections (A, B & C) I only want to count it as falling into section A as that is at the top of the rating scale. Any suggestions on a code that could help with this would be much appreciated. Thanks!Cal |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-07-21 : 00:05:52
|
[code]SELECT Category,COUNT(ID) AS CntFROM(SELECT *,ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Category) AS SeqFROM Table)tWHERE Seq=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|