Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet286/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   282   283   284   285   286   287   288   289   ...   443
Bog'liq
BookSQL

The 

GROUPING

 and 

GROUPING_ID

 Functions

When you have a single query that defines multiple grouping sets, you might need to be able to 

associate result rows and grouping sets—that is, to identify for each result row the grouping set 

it is associated with. As long as all grouping elements are defined as NOT NULL, this is easy. For 

example, consider the following query.

SELECT empid, custid, SUM(qty) AS sumqty 

FROM dbo.Orders 

GROUP BY CUBE(empid, custid);

This query produces the following output.

empid       custid    sumqty 

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

2           A         52 

3           A         20 

NULL        A         72 

1           B         20 

2           B         27 

NULL        B         47 

1           C         34 

3           C         22 

NULL        C         56 

3           D         30 

NULL        D         30 

NULL        NULL      205 

1           NULL      54 

2           NULL      79 

3           NULL      72

Because both the empid and custid columns were defined in the dbo.Orders table as NOT NULL, a 

NULL in those columns can only represent a placeholder, indicating that the column did not partici-

pate in the current grouping set. So, for example, all rows in which empid is not NULL and custid is 

not NULL are associated with the grouping set (empid, custid). All rows in which empid is not NULL 

and custid is NULL are associated with the grouping set (empid), and so on. Some people override the 

presentation of NULL marks with ALL or a similar designator, provided that the original columns are 

not nullable. This helps for reporting.

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   282   283   284   285   286   287   288   289   ...   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