Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet71/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   67   68   69   70   71   72   73   74   ...   443
Bog'liq
BookSQL

1. 

FROM

2. 

WHERE

3. 

GROUP BY

4. 

HAVING

5. 

SELECT

6. 

ORDER BY

So even though syntactically the sample query in Listing 2-1 starts with a SELECT clause, logically 

its clauses are processed in the following order.

FROM Sales.Orders 

WHERE custid = 71 

GROUP BY empid, YEAR(orderdate) 

HAVING COUNT(*) > 1 

SELECT empid, YEAR(orderdate) AS orderyear, COUNT(*) AS numorders 

ORDER BY empid, orderyear

Or, to present it in a more readable manner, here’s what the statement does:



1. 

Queries the rows from the Sales.Orders table



2. 

Filters only orders where the customer ID is equal to 71



3. 

Groups the orders by employee ID and order year

4. 

Filters only groups (employee ID and order year) having more than one order



5. 

Selects (returns) for each group the employee ID, order year, and number of orders

6. 

Orders (sorts) the rows in the output by employee ID and order year

You cannot write the query in correct logical order. You have to start with the SELECT clause as 

shown in Listing 2-1. There’s reason behind this discrepancy between the keyed-in order and the 

logical processing order of the clauses. The designers of SQL envisioned a declarative language with 

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   67   68   69   70   71   72   73   74   ...   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