Ekim 08, 2010

PARTITION BY & ROW_NUMBER() kullanımı

Bazen  kendi içerisinde gruplanmış,o grup içerisinde sıralanmış ve satır sayısı sınırlandırımış sonuç  döndürmek isteyebilirz.Mesela XXX dersinde en yüksek not alan 3 öğrenciyi sınıflara göre gruplayarak getirmemiz isteniyor olduğunu varsayalım.Ve PARTITION BY ve ROW_NUMBER() ifadelerini kullanarak bu sonucu elde edelim.

Öğrenciler
SINIFI OGRENCINO NOTU
11 1 95
10 2 62
11 3 44
9 4 50
9 5 85
9 6 100
9 7 25
11 8 10
11 9 100
10 10 75
11 11 30
10 12 52
10 13 65
11 14 99
Select * From ( Select öğr.*, ROW_NUMBER() OVER (PARTITION BY SINIFI ORDER BY NOTU DESC) satirsayi From Öğrenciler öğr) Where satirsayi < 4
Sorgu bize aşağıdaki sonucu döndürür.

Hiç yorum yok:

Yorum Gönder

System.Text.Json.JsonException hatası - cycle or if the object depth is larger than the maximum allowed depth of 32.

 Eğer .net'te aşağıdaki hatayı alıyorsanız; " A possible object cycle was detected which is not supported. This can either be due t...