Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet283/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   279   280   281   282   283   284   285   286   ...   443
Bog'liq
BookSQL

The 

GROUPING SETS

 Subclause

The GROUPING SETS subclause is a powerful enhancement to the GROUP BY clause that is used 

mainly in reporting and data warehousing. By using this subclause, you can define multiple grouping 

sets in the same query. Simply list the grouping sets that you want to define, separated by commas 

within the parentheses of the GROUPING SETS subclause, and for each grouping set list the members 

separated by commas within parentheses. For example, the following query defines four grouping 

sets: (empid, custid)(empid)(custid), and ().

SELECT empid, custid, SUM(qty) AS sumqty 

FROM dbo.Orders 

GROUP BY 

  GROUPING SETS 

  ( 


    (empid, custid), 

    (empid), 

    (custid), 

    () 


  );

This query is a logical equivalent of the previous solution that unified the result sets of four ag-

gregate queries, returning the same output. This query, though, has two main advantages over the 

previous solution—obviously it requires much less code, and SQL Server will optimize the number of 

times it scans the source table and won’t necessarily scan it separately for each grouping set.


Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   279   280   281   282   283   284   285   286   ...   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