@@ -53,42 +53,42 @@ Open [!INCLUDE [name-sos-short](../../includes/name-sos-short.md)] and have a lo
5353
54541 . In the same terminal window, run the following command:
5555
56- ```bash
57- sqlcmd open ads
58- ```
56+ ```bash
57+ sqlcmd open ads
58+ ```
5959
60601 . Now that you have a local copy of your database, you can run queries. Here is a query you can use to analyze spending by customer:
6161
6262 ``` sql
63- SELECT bg .BuyingGroupName
63+ SELECT bg .BuyingGroupName AS CustomerName
6464 ,COUNT (DISTINCT i .InvoiceID ) AS InvoiceCount
6565 ,COUNT (il .InvoiceLineID ) AS InvoiceLineCount
6666 ,SUM (il .LineProfit ) AS Profit
6767 ,SUM (il .ExtendedPrice ) AS ExtendedPrice
68- FROM Sales .Invoices i
69- INNER JOIN Sales .Customers c
70- ON i .CustomerID = c .CustomerID
68+ FROM Sales .Invoices i
69+ INNER JOIN Sales .Customers c
70+ ON i .CustomerID = c .CustomerID
7171 INNER JOIN Sales .InvoiceLines il
7272 ON i .InvoiceID = il .InvoiceID
7373 INNER JOIN Sales .BuyingGroups bg
7474 ON c .BuyingGroupID = bg .BuyingGroupID
75- GROUP BY bg .BuyingGroupName
76- UNION
77- SELECT c .CustomerName
75+ GROUP BY bg .BuyingGroupName
76+ UNION
77+ SELECT c .CustomerName
7878 ,COUNT (DISTINCT i .InvoiceID ) AS InvoiceCount
7979 ,COUNT (il .InvoiceLineID ) AS InvoiceLineCount
8080 ,SUM (il .LineProfit ) AS Profit
8181 ,SUM (il .ExtendedPrice ) AS ExtendedPrice
82- FROM Sales .Invoices i
83- INNER JOIN Sales .Customers c
84- ON i .CustomerID = c .CustomerID
85- INNER JOIN Sales .InvoiceLines il
86- ON i .InvoiceID = il .InvoiceID
87- LEFT JOIN Sales .BuyingGroups bg
82+ FROM Sales .Invoices i
83+ INNER JOIN Sales .Customers c
84+ ON i .CustomerID = c .CustomerID
85+ INNER JOIN Sales .InvoiceLines il
86+ ON i .InvoiceID = il .InvoiceID
87+ LEFT JOIN Sales .BuyingGroups bg
8888 ON c .BuyingGroupID = bg .BuyingGroupID
89- WHERE bg .BuyingGroupID IS NULL
90- GROUP BY c .CustomerName
91- ORDER BY Profit DESC
89+ WHERE bg .BuyingGroupID IS NULL
90+ GROUP BY c .CustomerName
91+ ORDER BY Profit DESC
9292 ```
9393
9494## How did we solve the problem?
0 commit comments