Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet238/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   234   235   236   237   238   239   240   241   ...   443
Bog'liq
BookSQL

 

CHAPTER 5

 

Table Expressions



 

 187

Solutions

This section provides solutions to the exercises in the preceding section.



1-1

This exercise is just a preliminary step required for the next exercise. This step involves writing a query 

that returns the maximum order date for each employee.

USE TSQL2012; 

 

SELECT empid, MAX(orderdate) AS maxorderdate 



FROM Sales.Orders 

GROUP BY empid;



1-2

This exercise requires you to use the query from the previous step to define a derived table and join 

this derived table with the Orders table to return the orders with the maximum order date for each 

employee, like the following.

SELECT O.empid, O.orderdate, O.orderid, O.custid 

FROM Sales.Orders AS O 

  JOIN (SELECT empid, MAX(orderdate) AS maxorderdate 

        FROM Sales.Orders 

        GROUP BY empid) AS D 

    ON O.empid = D.empid 

    AND O.orderdate = D.maxorderdate;

2-1

This exercise is a preliminary step for the next exercise. It requires you to query the Orders table and 

calculate row numbers based on orderdate, orderid ordering, like the following.

SELECT orderid, orderdate, custid, empid, 

  ROW_NUMBER() OVER(ORDER BY orderdate, orderid) AS rownum 

FROM Sales.Orders;

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   234   235   236   237   238   239   240   241   ...   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