Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet215/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   211   212   213   214   215   216   217   218   ...   443
Bog'liq
BookSQL

 

CHAPTER 5

 

Table Expressions



 

 163

This query joins two instances of a table expression to create two derived tables: The first derived 

table, Cur, represents current years, and the second derived table, Prv, represents previous years. The 

join condition Cur.orderyear = Prv.orderyear + 1 ensures that each row from the first derived table 

matches with the previous year of the second. Because the code makes the join a LEFT outer join, 

the first year that has no previous year is also returned from the Cur table. The SELECT clause of the 

outer query calculates the difference between the number of customers handled in the current and 

previous years.

The code in Listing 5-3 produces the following output.

orderyear   curnumcusts prvnumcusts growth 

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

2006        67          NULL        NULL 

2007        86          67          19 

2008        81          86          –5

The fact that you cannot refer to multiple instances of the same derived table forces you to main-

tain multiple copies of the same query definition. This leads to lengthy code that is hard to maintain 

and is prone to errors.


Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   211   212   213   214   215   216   217   218   ...   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