Sql server® 2012 t-sql fundamentals



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

Multiple references

Another problematic aspect of derived tables stems from the fact that derived tables are defined in 

the FROM clause of the outer query and not prior to the outer query. As far as the FROM clause of 

the outer query is concerned, the derived table doesn’t exist yet; therefore, if you need to refer to 

multiple instances of the derived table, you can’t. Instead, you have to define multiple derived tables 

based on the same query. The query in Listing 5-3 provides an example.



LISTING 5-3

  Multiple Derived Tables Based on the Same Query

SELECT Cur.orderyear,  

  Cur.numcusts AS curnumcusts, Prv.numcusts AS prvnumcusts, 

  Cur.numcusts - Prv.numcusts AS growth 

FROM (SELECT YEAR(orderdate) AS orderyear, 

        COUNT(DISTINCT custid) AS numcusts 

      FROM Sales.Orders 

      GROUP BY YEAR(orderdate)) AS Cur 

  LEFT OUTER JOIN 

     (SELECT YEAR(orderdate) AS orderyear, 

        COUNT(DISTINCT custid) AS numcusts 

      FROM Sales.Orders 

      GROUP BY YEAR(orderdate)) AS Prv 

    ON Cur.orderyear = Prv.orderyear + 1;

www.it-ebooks.info





Download 10,93 Mb.

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