Adventure Works 2014データベースを使用してSQLクエリを作成しています。Adventure Works 2014 SQLクエリ
私は、すべての顧客と各顧客の注文数を表示します。
私はそれぞれのselect文を単独で書くことを試みましたが(下記参照)、両方の質問を1つにまとめたいと思っています。
select s.CustomerID ,p.FirstName +' '+p.LastName as Name
from Sales.Customer s,Person.Person p
where s.CustomerID=p.BusinessEntityID
order by s.CustomerID
select CustomerID ,count(SalesOrderID) as OrdersCount
from Sales.SalesOrderHeader
group by CustomerID
明示的な 'JOIN' sintaxisの使用を推進し、アーロンバートランドは、[キックする悪い習慣:使用して古いスタイル・ジョイン]素敵な記事を書いた(http://sqlblog.com/blogs/aaron_bertrand/ archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx)を参照してください。 –
[Northwind SQLの顧客一人当たりの注文総数]の可能な複製(https://stackoverflow.com/questions/44084941/northwind-sql-total-orders-per-customer) – r2d2oid