Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet207/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   203   204   205   206   207   208   209   210   ...   443
Bog'liq
BookSQL

 

CHAPTER 4

 

Subqueries



 

 155

8

When I need to solve querying problems, I often find it useful to rephrase the original request in a 

more technical way so that it will be more convenient to translate the request to a T-SQL query. To 

solve the current exercise, you can first try to express the request “return a running total quantity for 

each customer and month” differently—in a more technical manner. For each customer, return the 

customer ID, month, the sum of the quantity for that month, and the sum of all months less than or 

equal to the current month. The rephrased request can be translated to the following T-SQL query 

quite literally.

SELECT custid, ordermonth, qty, 

  (SELECT SUM(O2.qty) 

   FROM Sales.CustOrders AS O2 

   WHERE O2.custid = O1.custid 

     AND O2.ordermonth <= O1.ordermonth) AS runqty 

FROM Sales.CustOrders AS O1 

ORDER BY custid, ordermonth;

www.it-ebooks.info




www.it-ebooks.info



Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   203   204   205   206   207   208   209   210   ...   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