Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet263/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   259   260   261   262   263   264   265   266   ...   443
Bog'liq
BookSQL

See Also  Because window functions are so profound and so useful, I wrote an entire book on the subject called 

Microsoft SQL Server 2012 High-Performance T-SQL Using Window Functions (Microsoft Press, 2012). In that 



book, I do get into the gory details, optimization, and lots of practical uses.

ranking Window Functions

Ranking window functions allow you to rank each row in respect to others in several different ways. 

SQL Server supports four ranking functions: ROW_NUMBER, RANK, DENSE_RANK, and NTILE. The fol-

lowing query demonstrates the use of these functions.

SELECT orderid, custid, val, 

  ROW_NUMBER() OVER(ORDER BY val) AS rownum, 

  RANK()       OVER(ORDER BY val) AS rank, 

  DENSE_RANK() OVER(ORDER BY val) AS dense_rank, 

  NTILE(100)   OVER(ORDER BY val) AS ntile 

FROM Sales.OrderValues 

ORDER BY val;

This query generates the following output, shown here in abbreviated form.

orderid     custid      val       rownum  rank    dense_rank ntile 

----------- ----------- --------- ------- ------- ---------- ----- 

10782       12          12.50     1       1       1          1 

10807       27          18.40     2       2       2          1 

10586       66          23.80     3       3       3          1 

10767       76          28.00     4       4       4          1 

10898       54          30.00     5       5       5          1 

10900       88          33.75     6       6       6          1 

10883       48          36.00     7       7       7          1 

11051       41          36.00     8       7       7          1 

10815       71          40.00     9       9       8          1 

10674       38          45.00     10      10      9          1 

... 

10691       63          10164.80  821     821     786        10 



10540       63          10191.70  822     822     787        10 

10479       65          10495.60  823     823     788        10 

10897       37          10835.24  824     824     789        10 

10817       39          10952.85  825     825     790        10 

10417       73          11188.40  826     826     791        10 

10889       65          11380.00  827     827     792        10 

11030       71          12615.05  828     828     793        10 

10981       34          15810.00  829     829     794        10 

10865       63          16387.50  830     830     795        10 

 

(830 row(s) affected)



www.it-ebooks.info



Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   259   260   261   262   263   264   265   266   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish