Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet172/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   168   169   170   171   172   173   174   175   ...   443
Bog'liq
BookSQL

Using the 

COUNT

 aggregate with Outer Joins

Another common logical bug involves using COUNT with outer joins. When you group the result of 

an outer join and use the COUNT(*) aggregate, the aggregate takes into consideration both inner 

rows and outer rows, because it counts rows regardless of their contents. Usually, you’re not supposed 

to take outer rows into consideration for the purposes of counting. For example, the following query 

is supposed to return the count of orders for each customer.

SELECT C.custid, COUNT(*) AS numorders 

FROM Sales.Customers AS C 

  LEFT OUTER JOIN Sales.Orders AS O 

    ON C.custid = O.custid 

GROUP BY C.custid;

However, the COUNT(*) aggregate counts rows regardless of their meaning or contents, and cus-

tomers who did not place orders—such as customers 22 and 57—each have an outer row in the result 

of the join. As you can see in the output of the query, shown here in abbreviated form, both 22 and 

57 show up with a count of 1, whereas the number of orders they placed is actually 0.

www.it-ebooks.info





Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   168   169   170   171   172   173   174   175   ...   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