Sql server® 2012 t-sql fundamentals


   Microsoft SQL Server 2012 T-SQL Fundamentals 5



Download 10,93 Mb.
Pdf ko'rish
bet291/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   287   288   289   290   291   292   293   294   ...   443
Bog'liq
BookSQL

242  

Microsoft SQL Server 2012 T-SQL Fundamentals



5

Write a query against the dbo.Orders table that returns the total quantities for each: (employee, 

customer, and order year), (employee and order year), and (customer and order year). Include a result 

column in the output that uniquely identifies the grouping set with which the current row is associated.



Tables involved: TSQL2012 database and dbo.Orders table



Desired output:



groupingset    empid       custid    orderyear   sumqty 

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

0              2           A         2007        12 

0              3           A         2007        10 

4              NULL        A         2007        22 

0              2           A         2008        40 

4              NULL        A         2008        40 

0              3           A         2009        10 

4              NULL        A         2009        10 

0              1           B         2007        20 

4              NULL        B         2007        20 

0              2           B         2008        12 

4              NULL        B         2008        12 

0              2           B         2009        15 

4              NULL        B         2009        15 

0              3           C         2007        22 

4              NULL        C         2007        22 

0              1           C         2008        14 

4              NULL        C         2008        14 

0              1           C         2009        20 

4              NULL        C         2009        20 

0              3           D         2009        30 

4              NULL        D         2009        30 

2              1           NULL      2007        20 

2              2           NULL      2007        12 

2              3           NULL      2007        32 

2              1           NULL      2008        14 

2              2           NULL      2008        52 

2              1           NULL      2009        20 

2              2           NULL      2009        15 

2              3           NULL      2009        40 

 

(29 row(s) affected)



When you are done with the exercises in this chapter, run the following code for cleanup.

IF OBJECT_ID('dbo.Orders', 'U') IS NOT NULL DROP TABLE dbo.Orders;

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   287   288   289   290   291   292   293   294   ...   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