thursday'snotes
this site the web

Lesson #3 :Ranked Group Data

Rangking adalah baris bernomor dari sekumpulan data dengan tipe rangking dan qualifier tertentu.

1. fungsi Rank :

Menambahkan rank berdasarkan nilai kuantitas di database. Misalnya list Top Ten customer berdasarkan jumlah pembelian

Contoh : SELECT [kolomName],  [kolomName] RANK () OVER (PARTITION BY [kolom pengelompokan] ORDER BY [kolom kategori]) AS [kolom rank] FROM [table] JOIN [kolom join table AB ] ON [kolom join table A ] = [kolom join table B ]

2. fungsi  DENSE RANK :
Menyediakan ranking terkategori tanpa ada gap apapun. Seperti RANK tetapi item yang sama dapat di tempat yang sama

Contoh : SELECT [kolomName],  [kolomName] DENSE_RANK () OVER (PARTITION BY [kolom pengelompokan] ORDER BY [kolom kategori]) AS [kolom rank] FROM [table] JOIN [kolom join table AB ] ON [kolom join table A ] = [kolom join table B ]

3. fungsi Row Number
Menyediakan kategori dan rank dalam 1 result set. Urutan dimana rank di assigned  ditentukan berdasarkan ORDER BY clause. Dapat digunakan dengan atau tanpa PARTITION. Jika menggunakan PARTITION, kolom yang digunakan adalah dimana ROW_SET kolom diaplikasikan. Misalnya  contact  pembeli dalam urutan custom.


Contoh : SELECT [kolomName],  [kolomName] ROW_NUMBER () OVER (PARTITION BY [kolom pengelompokan] ORDER BY [kolom kategori]) AS [kolom rank] FROM [table] JOIN [kolom join table AB ] ON [kolom join table A ] = [kolom join table B ]



4. fungsi NTILE
Menyediakan kemampuan mendistribusikan row pada partisi yang berurutan ke dalam grup yang ditentukan. Misalnya menentukan faktor yang digunakan untuk gruping atau pembagian tim sales berdasarkan sales figure. Biasa digunakan di datawarehousing. untuk setiap  row, NTILE akan mengembalikan nomor grup dimana row tersebut berada.

Contoh : SELECT [kolomName],  [kolomName] NTILE ([number of groups]) OVER (PARTITION BY [kolom pengelompokan] ORDER BY [kolom kategori]) AS [kolom rank] FROM [table] JOIN [kolom join table AB ] ON [kolom join table A ] = [kolom join table B ]



0 comments:

Post a Comment

 

Disclaimer

I do not claim any of these images as my own unless otherwise stated

The views and opinions expressed on this blog are 100% mine. If I claim or appear to be an expert on a certain topic or product or service area, I will only endorse products or services that I believe, based on my expertise, are worthy of such endorsement. Any product claim, statistic, quote or other representation about a product or service should be verified with the manufacturer or provide

About Thursday's Notes

This blog is a personal blog written and edited by me, and does not reflect the views of either employers and/or clients. This blog does not accept any form of cash advertising, sponsorship, or paid topic insertions.