Laden...

Sowas wie ROWNUMBER OVER (UNIQUE ColumnName)

Erstellt von TheBrainiac vor 10 Jahren Letzter Beitrag vor 10 Jahren 501 Views
TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 10 Jahren
Sowas wie ROWNUMBER OVER (UNIQUE ColumnName)

verwendetes Datenbanksystem: TSQL

Hi @ All.

Kleines Problem. Habe eine Abfrage, die schematisch etwa Folgendes liefert:

ID	Value
1	a
1	b
2	c
3	d
3	e

Nun brauche ich aber Folgendes:

ID	Value	Number
1	a	1
1	b	2
2	c	1
3	d	1
3	e	2

Wie kann ich die letzte Spalte bewerkstelligen? Ich brauche praktisch irgendwas, dass die Zeilen mit der gleichen ID hochzählt...

Gruß, Christian.

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`
F
115 Beiträge seit 2012
vor 10 Jahren

Hi,

das geht z.B. mit den analytischen Funktionen:

OVER Clause (Transact-SQL)

SELECT ROW_NUMBER() OVER(PARTITION BY id ORDER BY value) FROM table

Gruß
f_igy

TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 10 Jahren

Ahhhhh,

PARTITION BY war das Stichwort...

Danke!

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`