SQL学习之高级联结(自联结、自然联结、外联接)

时间:2022-10-01 15:06:20
create table Customers(
Id int identity(1000000,1),
Company varchar(30) null,
Name varchar(20) null
)
insert into Customers values('Fun4All','Tom')
insert into Customers values('Alibaba','Tim')
insert into Customers values('BaiDu','Jerry')
insert into Customers values('G0ogle','Herry')
insert into Customers values('Tencent','MaHuaTeng')
insert into Customers values('Fun4All','Bill')

这是讲解所需要的sql脚本

一、自联结       代码如下:

select * from Customers

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAACUCAIAAAAI4sImAAAPFUlEQVR4nO1d3Y7bNhrlQ7UDxe9SFJEGepACBRrbAXyzr1Cg2G4izwJ6hl4UCOr5uTGwbdo0zV4s5qcZe+zxgHshiqL4I4qSKOvTfAfCRKEl8ejjMUWJ37EIBYVX83/g8swXcmwRIhBuIJTSf/7r37jgAmVhkvX6tbi7u/N6/M4BjjCFybkB7u7uULIagCNMYXJugJ4ke3t76/X4nQMcYQqTcwPc3t6iZDUAR5jC5NwAx5PsejGZLNbVJceDtvnXiwnJEaf9k7JAH2QixHRIEW6MniR7c3MjFw1bsirhcuun8fBUqw8yIQXtIUW4MW5ubvqQ7PX1tVw0bMkqhIdEzgBTkBdx/u0CcBJ2XF9fM8k+Ph62D3sfy+Hw9Nen/8rHv3wdBK8vshV+uc1Kjr1oCHO20lKQP03YZqdRQAghwfxsxlauxHK25cM+ifhpk2jJqphFRUkSERKdbfONg/lVwyCLoQ5eX+ir1tEuneCL2eVQmoZJdv942Gx3PpbD4enPj3/Jx7+YB8H8fHs1DUiY7Dbb3SY5JcH83A+HtoQZW2nLgvz5LCDRcnMxD0gwvdiVVoL5Of8v31INxcU8IHkoipLTZLvbbJchW2kW5F0SkTDRnYVET6K9vZoGjLYhAsdpGu+SfXp6+vDnR300xUAMIyh6wlpuKnleIq1IW2b6u5gLlxd9KJjUklNZ5U5B3u4222Uo0dNWrdImInL5HrtpcsnuH+83Dz6Ww9PTHx8+ysc/nwfBfJX9FUv8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oABJYsABpQsAhhQsghgQMkigAEliwAGlCwCGFCyCGBAySKAASWLAIb/Axl+BuYybD8uAAAAAElFTkSuQmCC" alt="" />

现在有个需求,需要给Tom同一公司的所有会员发送一条邮件。

分析下基本思路,首先根据Tom找到其所在的公司名,在根据公司名找到其公司民下的所有会员。下面是解决代码:

select *
from Customers
where Company in(select Company from Customers where Name='Tom')

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAABBCAIAAAAMp+wQAAAG4klEQVR4nO1c24rbOhTdH9UGnfxLKbUHf0ih0Dop5CsKhTLj9MHf0IdCaZKZl8DpfTrn4TCXTuLEcVAffJMlO44v25ZaLURQ9ijW0vaabcVZCVA03N3d4R0cA8oRphJwDgkA9gQKQTnCVALO6DK6vb3FOzgGlCNMJeAcEtAySqEcYSoB5z5ktJwMh5Pl4Uh/yD0ly8kQYlhu96RKkJ9kYHKKnGF0Gd3c3PAhuWUkEs6eEdeST0n5SQZIaSNnOCSAKKPr62s+JLeMBMIykStAUZInVqx45EWEBMDb+BgtCPY/r/7b7YJM/PwlIS8XYSe5VISRvlsO4YQt11LyJ0407MQkAABk/HYUdS7YeDRy4ztmsmwwp9EUIzONOCaA+daLB5PxRc0ks6kmLxf5U+fRzizwn9F5edIopbD2thgtCPY/Ln/6uyATX4wJGc+9C5uA4WzX3nbtnAAZz3E4NCUcseVGpuTnIwLmdL0YEyD2YpvpkPE8eZqMFFOxGBOIU5FGThxvu/amRtSpl+StY4Lh5K2Co8fR9i5sEtEuyABPAFFG+/3++4/L/BWy5MqIdtZyCOdyE8knEa7DjQw1sRgzZTg/FdHpd0545VVKsrdde1ODo5c7tUgbWMSSKiZAKYXVeoPRgv3+2/dL399l4vMxIeNZ+MhGcDg0JnxuE2LPsyNF8kmE6+Qsc2pAfMADqXBMMKZnhjB1pSSvN6v1ZmYTYpglU4u0wTyrkrSeZLQ+twkYTrROkFdGHL2pAWA4WfLGlD8NeecjGrmeGskZckwo/I+aGgDHpKVURsyhiqfmO+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B8uumqBJtFw0gV+9+hU6KciZY9e+ws3ciIY9JkrgrVSOy2FamyBgQZ9WeizRQBwS7SuowKTLS+t7kYETCnjUy0Bzm4ub+5W2TgqRdha3tp3o6VkRIm2o6rUYH7cTsfkYa/ESuFjNKNSfk1+rh9hiImWnFv1L2MmmtIFhllE3s4dQ2rkVwmWvGihisjwf3Y1s96SrE3YtCtjJY9m2gzMhLmQpeRY0Jj+2xlGaG9U2OSKZgPi5PCg0+6CiZabm+EXY04E+2pkfkfOub3UA+YaA9y6Oa+URppbYuthIk2Ww3TPRqSjFBNtI15dgrlCNO+OTMywjTR9rjCGlCOMO2bcyojVBNtjyusAeUI0745pzJCNdH2uMIaUI4w7Zszexcb0UTb4wprQDnCtG/OqYzq2yc1/nokelLPxK4hIbSMNFqAlpFGC9Ay0mgBWkYaLUDLSKMFaBlptAAtI40W8BsU26qB1X4Q9gAAAABJRU5ErkJggg==" alt="" />

ok,通过子查询轻松的完成需求!

但是这边有一个重点,你必须要知道,子查询虽然方便,但是大多数DBMS的处理子查询的速度比处理联结要慢的多,如果数据量少的话,几乎没什么影响,但是如果后期数据会很大的话,就应该使用自联结!

下面是使用自联结的解决代码:

select *
from Customers c1,Customers c2
where c1.Company=c2.Company

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAacAAACtCAIAAACbYScdAAAYSklEQVR4nO1dvW7jyhmdFwmSJ1AlGLx+gxQpYrVREcpwm8LYVGmy3ZW1gA34GVyuJRd+BhUGhPivMZDkJjf3KtVqN9eS7bWxKfg3JId/Qw75ndE3+GBouRTnnG+OPnJG4qH4ZrJ9+fLF6PEbb3CAv2FirtqwOGKh9RoiZo325cuXq+VCmO7D6PEbb3CAv2FirtqwOGKh9RoiZo3WRtX7/Pmz0eM33uAAf8PEXLVhccRC6zVEzBrt8+fPXPWSDQ7wN0zMVRsWRyy0XkPErNE6qnoPx7u7xw/5W7pryrF/ON4VQTu4bB9UQVMnWUg5pZRhvYYlJFYR2dZG1VutVslNhMX6T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Tq3CR0KsUo/b5SCfnpvg6xVCSKwimhGvenEvZdk7vqaPPInlmNJibVqv7P3dvF4hhMQqohl5Ve9xOhLO5Nr3kRfuFNtBvrzxdwW9svd3u4ElJFYRzYhVvbSD/Ec3OLPU85Gn8TOrssbfBWOfkmAwv2Dv7/b0CiEkVhHNiFU9dpAvHnvCgYjZbo5YaHExa3NkB3l1XoACEbPdHLHQ4mLW5sgO8uq8AAUiZrs5YqHFxazNkR3k1XkBCkTMdnPEQouLWZsjO8ir8wIUiJjt5oiFFhezNkd2kOfGjdtWtLD8ic4LMAcHB0ebwVWPg4Nju+L/CkWP50Q5lmgAAAAASUVORK5CYII=" alt="" />

这是自联结之后的效果!

select *
from Customers c1,Customers c2
where c1.Company=c2.Company
and c2.Name='Tom'

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWIAAAA9CAIAAAAYkfS7AAAIyUlEQVR4nO1c227bOBDlR7UG1/9SFJUCfUiBAq3sAv6KAsV2UzkL6Bv6UKCo7eTFwPZ+2YdFkzSWbEeG9oGURN2smylynDkgAoaRycOZ8dFIkYaECAQCsRckDMM///obGzZs2MoalwmpUnR9fS11/oMDHOFQNWdYFoPFlkEtZ5SJAoAjHKrmDMtisNgyHL9MXF1dSZ3/4ABHOFTNGZbFYLFlUMsZZaIA4AiHqjnDshgstgx3UiaWk+Fwstw/og6FLllOhiSC5fZPqgLFRiaCTWVaGJaL0b9N0YdMXF5eZoc0jqGwiHDaI66lXyQVG5mQhLZMC8NyMfq3KfqQiV+/fmWHNI6hsICwTuRKUGbkiRVFvMxNwHIx+rcpuEzc3gb+eiujBcHux89/s/OfP6f0+YJ14lSPjahuBYRjtpmWkD9x+GEnJiWEEDo+G/HOhTjOj1xvHTPeNjGnfImRmYw4JiHmmR8dTMcXLY0smpo+XxQvXUQ7tcE/RudH4mL0b1P/+ustl4ntbeD5GxktCHbfvv/Izr8YUzqe+xc2JYaz8fyN55wQOp7L4dCVMGebOTIhPx9RYk69xZgSai82qQ4d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b95qoUXHYeSiUyRu1MjpZEDe9GlyF3tHfbxT/VK+9S/E56cSrQtgpY+2yXX0KpkQvPnJsD5l+Moity1sowygCMcquYMy2Kw2DLo8hSm1CJ3CnfYAuAIh6o5w7IYLLYMusiE1CJ3CnfYAuAIh6o5w7IYLLYMusiE1CJ3CnfYAuAIh6o5w7IYLLYMusiE1CJ3CnfYAuAIh6o5w7IYLLYMusgEAoFAFILLhEKhQiAQmgNlAoFAVOB/FDAPHBiLAq0AAAAASUVORK5CYII=" alt="" />

这个是两张表(实际是一张表)联结之后的结果图,ok完成需求!

自联结通过联结的机制,将所有公司名相同的记录联结到一起,即每一个公司的会员,都会和同一公司的其他会员联结一次,因为他们的公司名相同,这是时候指定c2.name='Tom',就能拿到Tom和其公司所有会员的资料,这个时候就可以发邮件了!

二、自然联结

无论何时对表进行联结,应该至少有一列不止出现在一个表中(被联结的列)。标准的联结返回所有的数据,相同的列甚至出现多次。而自然联结就是排除多次出现,是每一列只出现一次。

但是SQL不提供这项功能,自然联结的功能是需要你自己去完成的,自然联结要求你只能选择哪些唯一的列,一般通过对一个表使用通配符(SELECT *),而对其他表的列使用明确的子集来完成。

注意:我们迄今为止建立的每个内联结都是自然联结,很可能永远都不会用到不是自然联结的内联结。

三、外联结(左外联结(LEFT OUTER JOIN)和右外联结(RIGHT OUTER JOIN))

许多联结将一个表中的行与另一个表中的行相关联,但有时候需要需要包含哪些没有关联的行。例如,有如下需求

(1)对每个顾客下的订单书进行计数,包括那些至今尚未下订单的顾客;

(2)列出所有产品以及订购数量,包括没有人订购的产皮

(3)计算平均销售规模,包括那些至今尚未下订单的顾客;

内联结代码如下:

select * from Customers
select * from Orders
select *
from Customers a INNER JOIN Orders b
ON a.Id=b.CustomerId

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUsAAAFqCAIAAAAcJe9aAAAgAElEQVR4nO2dy24bORaG+SjzBFoZAeM3mK29HW8kQy9gePaTXUsK4AB+Bm8GE0sewM/ghYAG5MvGwH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DhenoF2chI5O4St8Kv8eXha/uf4rHJHWjEBN4XBxUkyMEFycXNq8NHKU/lpn2lQDWSUCKYXDxUk5McJwcZoNOOtOHuaPD/NJl/HBpT8XJ/dn2gov7DE4b1w8qVux/YQUDhentrg4fezGH1eeXZxarPCpyG2nVvvpKBwuTnBxcjmf0hxEv5a5EjmuaduEjGggV3g7XZympR/Ay6pmumJTu337Wwq9jGggVThcnLzWTk8P9DKigVThcHHyWjs9PdDLiAaKa9rg4uSxdnp6oJcRDaQKR0FBIVCEsnd/ITcAIBygcAAoA4UDQBkoHADKQOEAUOb/B55Zwo4iukYAAAAASUVORK5CYII=" alt="" />

这边我们使用了内联结检索出所有用户的订单,通过内联结的检索结果和外联结的检索结果比较,来更好的理解外联结!

通过结果图,发现内联结确实把所有用户的订单都检索出来了,但是这里内联结似乎把没有订单的用户给过滤掉了,所以我们分析得出内联结只把有订单的所有用户信息包括订单信息检索出来,但是如果用户没有订单,则该用户信息会被过滤!

下面再来看外联结代码:

select * from Customers
select * from Orders select *
from Customers a LEFT OUTER JOIN Orders b
ON a.Id=b.CustomerId

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWkAAAF2CAIAAAAjmf5XAAAgAElEQVR4nO2dPW/jyJ7u66PsJ1ByjEa1sV9gUxs3uAfrhDKU3NDwpgfrbCQ1oAaMm96JnByctuQDKL6bORDQgPySGDgzPdPT0yey2zuWbLcMb0CKb/XCKhaLLJaewg8NNUVV/f/18piiyIfkr3/7OwAA6EJerZX7+3tHKjEMYPb1IwAgB7SjOIDGBwkAB7GoHd++fXOkEsMAGh8kABwE2lEcQOODBICD1KsdN6Pt7dGNfItKJST1maIaDAu0AwAuFrXj7u4uv0lfO/iVEJKoh2XtuLu7a3yQAHAQi9pxe3ub36SvHaJKRj3SmyrVYFhub28bHyQAHIQsH59tsFq9/P71n9+/rzLbr95R+u4yfEHWJdyiW0m6Kvru8vF53I1rJN1JuH2/SwkhhA7PBtGL62Wm9beDq+IsGh8kAByELJ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FVmxE8B+E5WOV8mmWPOCT7lHhLpfXGcTk2ZOQTYu1oredg/IJbZkXqAO1wDf8y8gPhGoTnoLOttzc2ZOQTQu2A56Czrbc3NmTkE5LrSuE56Gjr7Y0NGfmEUDv4HmMoKCgo68LXjirueitxL5yp5tWmuK+vn9zE5diQkU9AO6AdruNfRn4A7YB2uI5/GfmBt9ohuriD3Q3a4Tj+ZeQHOtoRuw6a+YeJlz3H/kxXO3QvGK1YO27+sk3+NLpJ/Xf7Lzevn15ff+yRP0+TPdf/TXZgP1J+RJ2NDRn5hLp2THtr0Zj2jAxLpdohu8VY8biD8O5kqVE7CImno3Pa0XBsyMgnlLXDUDBUtIO1PyulHSJdqEk7tv8y6pHetLHZ7HJsyMgnhNqR8xy8HL4l3TMTq8Fiz0HWPa0W7VA5LaKlHTfxjHRPO5qNDRn5hFA7cr5hFwNKu/uRZWl3Uto0TOY5KPFKKKsdonvhtJRCWzteP03DP4YOakejsSEjn9DQDvt+pQmFHhPlfqxhlcKSdry+/thL/0l0STsajA0Z+YRYO3Keg+Nu7DNox3OwSu0QKUKN2vHpZvSn7d6f1//9r9E27xeBZrSjsdiQkU8oa8diEpDu6eLxYXHVpyQYV+85yLE/K6Ud3C8mRODcYU87Xl9/7KV+BZjGp/ReP71O/0x6P/Lnbi3a0VRsyMgnhNrBeg7+cdqNVmEwtuQ5yNqf6WqHXAtUtKOCc6Xr/96M/pT8gvj6X6PttYylf1ZMy1vvR84W/RF1NrbSc9SzjPxAuAbb6znYpHY4gMuxISOfEGtHOz0HRZIRf22RvCvfDdqBjEAaoXbAcxDa4Qj+ZeQHQu2A5yC0wxH8y8gPJNeVwnMQ2uEE/mXkB0Lt4HuMoaCgoNzd3UkukmjwrzoAoL1AOwAAZfgfgyYsOW0ZtVMAAAAASUVORK5CYII=" alt="" />

这边我们使用了左外联结检索出所有用户的订单

通过结果图,发现外联结也把所有用户的订单都检索出来了,但是这里外联结把没有订单的用户也检索出来了(即外联结能检索出没有关联行的行,对应的用null来填充其关联行),只是它的订单信息没有,所以对应的用null来替换,这就是外联结和内联结的最主要的差别,我们可以根据不同的业务需求,来选择性的使用它们!

四、全外连接(FULL OUTER JOIN)

select * from Customers
select * from Orders
select *
from Customers a FULL OUTER JOIN Orders b
ON a.Id=b.CustomerId

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYsAAAGFCAIAAACDiEisAAAgAElEQVR4nO2dPW/jyJ7u66PsJ1ByjAbb2C+wqY0b3IN1IhlKbmh404N1NpIaUAPGpnciJxfblnwBx3czBwIakF8SA2emZ3p6+kR2944l2yPDNyBFFlkvLLFIVvHPp/DDjJoiq+pfL4+Lb4/YKxISEpKviYX/+z//+X8BAMA3EoWqVAi/f//uSSaWFZh9/QgAqA0o1GYVcN5hALSKmhTq27dvnmRiWQHnHQZAq4BCbVYB5x0GQKtwp1C34+3t8a1+i0kmjDsmLwfLBIUCoGZqUqj7+/vsps0VSp4JY4lGVaxQ9/f3zjsMgFZRk0Ld3d1lN22uUKpMxn3WPzfKwTLd3d057zAAWkWiUH/+uVo+PlfBavXy+9d/ZPO/fhcE767CD2ydwi2bZsJnFby7enye9OIcWW8abt/vBYwxFozOhtGHm2Wq9LfD6/wonHcYAK0iUajnP1eL5VMVrFYvv335PZv/1SgIRpfLm0HAupOnxfJpMdlnweiySCZPkx7rTpJ/Zne4GgUsGFw9LfgPUenB4CqVlT4K5x0GQKuoQ6FeXl4+//ZFLi68Lmg1QpfJ8mmxnHb53K5G3LosvZ3/wO/GGGNrtVJXwHmHAdAqOIV6/vNh8VgFq5eXXz9/yeZ/OQqC0Tz8L7+lQCaLx4fF43wQBN1eEIzmi2mXBYNLWSmZD5ejgPVON4nCeYcB0CpcK9TiehCw7iSSGGahUA+LaZcxFinUWncmPaZRKK70hzy1gkIBUD+JQj09//nHw7IKVquXT798zuY/H74JhvPwQ3SOFURbCmTysPzjYTkfBCwYzsMPyanbcM6XlfnwMOmu9/thnh+F8w4DoFUkCvX49PzffyyqYLV6+fnTr5b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aa3G6iqbeyDU37RecCnHD9LgjeXdm5AGukoTbrVU+q4YVCneyyveNcTy6DFUfDMFCoaEWQmZxcQyXSoGkH2eHxOkLzAyLiGursYEu6MhJONlMdmpZRaV8ngrLeWXTlzq/Gx9SqM324ug1N+0XnscmbbdoYbIYemzppqMt61ZNqeKBQ0Yi0UajO3m6H1nWoOLRwThoqlKod5IdHc1h5vhOXPkuu4KhWRrxCaTpU+ZVkTSRz5c6rBldn4fB6FGraZfsTC3kyUah6rFc9qYZzhYrHitUaqkaD+RLRKxQvEKZrqHQ7RPM5vWYRToKixVS8s1g6j+JKX1ooFR2q/irnh+DErKTVUNVZeq5qrVBZj80S/H9jj808aajDetWTarhWqPg6a3o9v9F8Ptk1HHm+oVGo7GQzuw6lbAfhcP10VU119d+AuBqaDlV+ldtrwg6SaqjrnHstz7RfchXqehAEg0sreTJUqBqsVz2phmuF0oxC8/mcmh4U1lAnu5JbY/L7UJLTK0k7iIdrftlIKD25wiVWTFKN/A5NfyW/sya6cuuqoalzfLOy3Ht5chdgO//f2AXYQBoqt171pBokFIra81DJYzvcWqP056FUDwfpSzd/Hkp+pVzsa25pk9lZdOUWqhHtrK+zeHgJz0NV6gLsfLrqFIooeKa8DRHRwEyhqnQBdj5doVAljpvmQi8iGhgpVKUuwM6nKxSqxHHTXOhFRAMjharUBdj5dIVClThumgu9iGhg+Ex5hS7AzqcrFKrEcdNc6EVEAyOFQkJCQnKSVMqVKJRzEQUAgAxQKACAv0ChAAD+AoUCAPjL/wd4mqn5rp4ZkQAAAABJRU5ErkJggg==" alt="" />

分析Orders和Customers表结果图发现:赵六和冯七没有下订单,而订单表中的第四单没有与之对应的顾客,再看全连接之后的结果图,发现全联结把所有没有没有与之对应关联行的行全部用null填充,这就是全联结的作用!

五、使用带聚集函数的联结

聚集函数是用来汇总数据,在我前面的随笔中所用的聚集函数的例子都是从一个表中汇总数据,其实聚集函数也可以和联结一起使用,其实联结是多个小表组装而成的一个大表(你可以这样理解).

下面通过例子来了解其用法,代码如下:

select * from Customers
select * from Orders

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQMAAADpCAIAAACvG8XMAAAUvklEQVR4nO2dS27bSB7G6yhzAq2MoOIbzDbZjjeU4QsY6X1n15IMOEDOkM1gYsoN+AxeCGhAD28MTHe60+nMyrQ7elpCZkGKKrIeLLJYZIn6Cj8YMkXV8/+pSIofi3y3kJ6enhzJxLACg6+/gAOBWIohRzIxrEDtwwMqw4oSHh8fHcnEsAK1Dw+oDChBVYHahwdURlVKuL88Pr68V2/RyYQwn8nKwTBBCQeFFSUEQZDelF8J4kwI2WnBshKCIKh9eEBlWFHCw8NDelN+JcgyuTwjZzdaORimh4eH2ocHVAaZL1blsl5v/vr6v+fndWL75ILSi3H4gmxTuCVvJmxW9GK8WPntOEfS7ofbT9uUEEJo77obvbibJ0p/2Z1kt6L24QGVQWbzZbms15s/v/y1el4nto97lPZG87sOJZ6/nM2XM/+U0N6oSCZLv008f/dveodxjxLaGS9n7IuodNoZJ7JSt6L24QGVUb4SNpvN5z+/iIOYjT9lLKoymS9n877H5jbuMfNMcjv7gt2NEEK2qpBXoPbhAZVBprNFuaw3mz8+f1mtnhPbRz1Ke8PwL7ulQCazxXS2GHYo9dqU9oazvkdoZyQqJfVi1KOkfZWnFbUPD6iMapUwm3Qo8fwolImBEqazvkcIiZSwjW+/TRRKYEqfZqkCSjg0yLfpvFzW682n3z8vV8+J7cPuC9odhi+iYxMabSmQyXT+bTofdiih3WH4YnfI0x2yZaVeTH1vu99Pw+xW1D48oDLI399m5bJeb3779Mdiuao9E/MK1D48oDLI09/Tclmv17/+9vtisao9E/MK1D48oDLI49O3cnler//766f5Yll7JuYVqH14QGWQCZI81T48oDLIs4W0Wq0cycSwArUPD6gMEthJhJBS/taYah8bUCW27kX98fInQ+qNRSjh0LClBEKIoRIIITX2C5RwaGBOEAMlHBpNmBNszB5QwqHBK+EmdsKYKEEZ5d4RefGvonMCezdpvCX1IrVbKun0C5RwaLBKCM2RhJ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7k2ZnU87bhSuRcfRUALcm8zxW33uzb5HTv35ctSltHtnx72pcPrpxo3Cteg4mUqAe9MJ92YsAHtKUDj99OOGdy1WHNCFUSsB7k3+g+pqWHJvTjo0cVZvwb2pcPrliRuFa9FtFEqAezNVnzrdm2WZmHV8zCZzgsq16DaqawBwbzrl3gwZdqg992Zmr2XHzdem/Z4A9ybcm0XiZn9pXouaQQD3Zi09DlwjgHuzlh4HrhHAvVlLjwPXCODerKXHgWsEcG8iIYVpAH9C9d89wDWghHp6HLgGlFBPjwPXgBLq6XHgGrwS4qU3iaFrTT7kAoudun5y9my5QXWL4N50yr1puuSmnhJ0w1eeicRA6DyyFsG9KY6N2tybpituaiiBt9jljxtpxzmPztER3JvprlBVg9mtTPfm5CJ2KNhyb/IOveJx00glwL3JxEZt7k3/lNDeyOqKg4q75HPHTQOVAPemE+7N1Fq0JgbOHIcBxeOmaUqAe1MRG1h7U5FDo5QA96YyNmpbe7PvEdoZWV17M30FI1fcpGNiT1AdNMK96ZR7c1/W3pQNhuPIWgT3JtybReJmf2lei5pBAPdmLT0OXCOAe7OWHgeuEcC9WUuPA9cI4N6spceBawRwbyIhBduvJ1K7IgFwASgBgF8GX3/5Pw2m/CNyCJotAAAAAElFTkSuQmCC" alt="" />

现在有个需求,需要检索出所有顾客的订单数量(没有则为0),下面是解决代码:

select a.Id,a.Name,COUNT(b.CustomerId)
from Customers a LEFT JOIN Orders b
ON a.Id=b.CustomerId
GROUP by a.Name,a.Id

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJsAAAByCAIAAADLSDSRAAAJIklEQVR4nO2dy07rOBjHv0eZJ+gKHfnwBrOF7bA4KeIFELMfdrRFAolnYNMp9CKdZ2CBdDS9sEGac7/M6oRL0wupOou0qZv4FjtOnRxbFkpd833Bv3yJY/+xod7ozHWmx8dHQ4zk1HvSBJao4d6TJu1EHx4eDDGSU+9JkyW6Ye8AwC1JZnADRO/PtrfP7tklIkYA+x2eBZVEIfr2AA7ezudAT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BEV1oGbUTP91IYBQRMg8LmJwGV4T1HO/jM5/PFNj56id4cldTGdeOjP0S6WojeHJUWwhq+DMMEovdn29sHB2qaFA7R9uFWaWePv/dNortuOPiXYjORv7rcDUPzfM+w/V4IqpTWPpTb/dprVLtT3MGHegaXu7B3IbKbkQpRfeO6+JkbtydTTMOw2OmlV0WoeqdHlbKYhFIhSsOTYoAWhGgIUh/RsAlSj1EaUW6nqVhE1zQMgwpau/A1qFJCpesiSatS4k9N2nNUhHoy7yY/R2k6I0WRkYjOSDFGYX0S9FbDm0wu+7qUHXxG3QrSp0pJlyibohaiJr+P5leVItJlZXyr0tc1MLsFUKVEuMa7vtKw803UqlKM9S5J1KpSjPUuSdSqUoz1LknUpsKkgsyP2hiNxqglaqx3S9QSLQRRwWkyuTmZYhBdbeCjqGKgN8fFDjZQL7cOQ9LBoNSJmjsKSCKquOyNCFHVVc1vKSO6GRE1eaQ+ykF1hRQBoqvmUCJKo5UFUZNn06KqlMFpOEOqS5Vyc1QSmxxNl6jI41bQu9kz3hFVSnN/udOLtpU1VitUpfNf+4yR+kT8CkqUpFDRtlZKaitrxBlzS4pLNM9rpdA46SZq9HOUvlZKywFU6WldK+ViR/btJYREu9/qJWpyXzena6WwCYkQVekZ3Zr8PppfVcpmiZqW3byrUmggGd3aFN9eDMyuVaWY712SqFWlGOtdkqhVpRjrXZKoTcVItz/e/Q+NjTl60womeAAAAABJRU5ErkJggg==" alt="" />

ok,完成需求!

六、使用联结和联结条件(使用联结主要注意的要点)

(1)注意所使用的联结类型。一般我们使用内联结(INNER JOIN)使用外联结同样有效!   ---这一点上面'三'已论述

(2)保证使用正确的联结条件(不管采用哪种语法、那种联结),否则会返回不正确的数据。

(3)所有的联结都需要提供联结条件,否则会得出笛卡尔积。

(4)在一个联结中可以包含多个表,甚至可以对每个联结采用不同的联结类型。这样做是合法的,也是有用的,但是在一起测试它们前分别测试每个联结。这样会使排除故障更简单。