{"id":2191,"date":"2012-10-03T17:12:00","date_gmt":"2012-10-03T17:12:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2012\/10\/03\/joining-multiple-tables-grouping-and-evaluating-totals\/"},"modified":"2019-02-18T13:05:35","modified_gmt":"2019-02-18T20:05:35","slug":"joining-multiple-tables-grouping-and-evaluating-totals","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/joining-multiple-tables-grouping-and-evaluating-totals\/","title":{"rendered":"Joining Multiple Tables, Grouping and Evaluating Totals"},"content":{"rendered":"<div class=\"WordSection1\">\n<p class=\"MsoNormal\"><b>Joining Multiple Tables, Grouping And Evaluating Totals<\/b><\/p>\n<p class=\"MsoNormal\">This is a continuation to the <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a> blog post considering multiple joins and SQL style grouping and total evaluation.<\/p>\n<p class=\"MsoNormal\"><b>Problem:<\/b><\/p>\n<p class=\"MsoNormal\">In the <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a> blog we&rsquo;ve seen that relational data naturally organizes in multiple tables.&nbsp;Once we have those tables, we frequently want to see&nbsp;the information back together, so we need something like <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a>. Sometimes we also need to group the information and evaluate totals inside the groups. For instance, what are the total sales for each customer?<\/p>\n<p class=\"MsoNormal\">How can we use <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a><span class=\"MsoHyperlink\"> <\/span>in multiple tables and group information from the tables to report totals?<\/p>\n<p class=\"MsoNormal\"><b>Joining multiple tables:<\/b><\/p>\n<p class=\"MsoNormal\">Consider the following tables describing sales at a fruit stand:<\/p>\n<div align=\"center\">\n<table class=\"MsoTableGrid\" style=\"border: currentColor;border-collapse: collapse\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"271\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 203.4pt\" colspan=\"3\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: normal\"><b>Customers<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Id<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Name<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Phone<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">John Smith<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">(206)555-8899<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">2<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Mark Stone<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">(425)999-8811<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">3<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Ruth Moore<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">(425)888-3355<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<div align=\"center\">\n<table class=\"MsoTableGrid\" style=\"border: currentColor;border-collapse: collapse\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"271\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 203.4pt\" colspan=\"3\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\"><b>Products<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Id<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Name<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Price<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Apple<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">10<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">2<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Orange<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">12<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">3<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Kiwi<\/p>\n<\/td>\n<td width=\"114\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 85.5pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">15<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"MsoNormal\"><span style=\"line-height: 115%;font-size: 7pt\">&nbsp;<\/span><\/p>\n<table align=\"center\" class=\"MsoTableGrid\" style=\"border: currentColor;margin-right: 6.75pt;margin-left: 6.75pt;border-collapse: collapse\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"319\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 239.4pt\" colspan=\"3\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\"><b>Orders<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Id<\/p>\n<\/td>\n<td width=\"174\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 130.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Date<\/p>\n<\/td>\n<td width=\"102\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 76.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">CustomerId<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<td width=\"174\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 130.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/6\/2012 9:12:44 AM<\/p>\n<\/td>\n<td width=\"102\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 76.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">2<\/p>\n<\/td>\n<td width=\"174\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 130.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/7\/2012 6:12:10 PM<\/p>\n<\/td>\n<td width=\"102\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 76.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">3<\/p>\n<\/td>\n<td width=\"174\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 130.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/5\/2012 12:05:03 PM<\/p>\n<\/td>\n<td width=\"102\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 76.5pt;text-align: center\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">2<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<table align=\"center\" class=\"MsoTableGrid\" style=\"border: currentColor;margin-right: 6.75pt;margin-left: 6.75pt;border-collapse: collapse\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"259\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 2.7in\" colspan=\"4\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\"><b>OrderItems<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"text-align: center;line-height: 115%;margin-bottom: 10pt\">Id<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"text-align: center;line-height: 115%;margin-bottom: 10pt\">Quantity<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"text-align: center;line-height: 115%;margin-bottom: 10pt\">ProductId<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"text-align: center;line-height: 115%;margin-bottom: 10pt\">OrderId<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">2<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">3<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">2<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">2<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">3<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">4<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">5<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">4<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">5<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">5<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">4<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">2<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"43\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.45in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">6<\/p>\n<\/td>\n<td width=\"72\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 0.75in\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<td width=\"78\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 58.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">1<\/p>\n<\/td>\n<td width=\"66\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 49.5pt\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\">3<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">As we saw in the <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a> blog, we need this many tables to deal with the simple conceptual problem of selling fruit!<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">One might question the need for the OrderItems table. An order item is a line in the receipt for an order that lists a product and its quantity. Since there can be many items per order, it needs its own table as mentioned in the <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a> blog.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">As we can see from the data, we have 3 customers, 3 products, 3 orders, and 6 order items. The three first order items are for the Order with Id 1.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Good data design forces us to split the tables, but after this is done, we frequently need to see the data together.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">For example, suppose I want a report with all basic receipt information, including customer name, order date, all products bought, their quantity, and price. Here is the SQL statement that produces the report:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">SELECT&nbsp;&nbsp;&nbsp;&nbsp; Customer.Name, [Order].Date, OrderItem.Quantity,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.Name AS [Product Name], Product.Price<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OrderItem INNER JOIN Product ON OrderItem.ProductId = Product.id INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Customer INNER JOIN&nbsp; [Order] ON Customer.id = [Order].CustomerId ON OrderItem.OrderId = [Order].id<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">Here is the result:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&nbsp;<\/p>\n<div align=\"center\">\n<table class=\"MsoTableGrid\" style=\"border: currentColor;border-collapse: collapse\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"559\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 419.4pt\" colspan=\"5\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: center;line-height: 115%\"><b>Joining All Tables<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Name<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Date<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Quantity<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Product Name<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Price<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">John Smith<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/6\/2012 9:12:44 AM<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">2<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Apple<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">10<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">John Smith<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/6\/2012 9:12:44 AM<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Orange<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">12<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">John Smith<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/6\/2012 9:12:44 AM<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">4<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Kiwi<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">5<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">John Smith<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/7\/2012 6:12:10 PM<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">5<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Apple<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">10<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">John Smith<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/7\/2012 6:12:10 PM<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">4<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Orange<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">12<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"115\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 1.2in\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Mark Stone<\/p>\n<\/td>\n<td width=\"156\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 117pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">6\/5\/2012 12:00:00 AM<\/p>\n<\/td>\n<td width=\"112\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 83.85pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">1<\/p>\n<\/td>\n<td width=\"128\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 95.75pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">Apple<\/p>\n<\/td>\n<td width=\"49\" valign=\"top\" style=\"padding: 0in 5.4pt;width: 36.4pt\">\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal\">10<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\"><b>A little explanation of the SQL statement<\/b><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The&nbsp; &ldquo;AS [Product Name]&rdquo; segment sets the column name in the output. Both product name and customer name are called &ldquo;Name&rdquo; in their own tables, so we need to differentiate them in the output.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The brackets around &ldquo;[Order]&rdquo; differentiate it from the SQL &#8220;Order&#8221; keyword.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The Inner Join shows only the items present in both tables.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">All 4 tables are &ldquo;inner joined&rdquo; in the statement.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\"><b>&nbsp;<\/b><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\"><b>Putting the data in Windows PowerShell<\/b><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">From here on, we will use Windows PowerShell to manipulate this data, so let&rsquo;s start by putting this data in PowerShell.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The following script creates four CSV files and then imports them into four variables that contain our data.<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">@&#8221;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">Id,Name,Phone<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">1,John Smith,(206)555-8899<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">2,Mark Stone,(425)999-8811<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">3,Ruth Moore,(425)888-3355<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;@<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">&gt;<\/span> <span style=\"color: blueviolet\">c:\\temp\\customers.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$customers<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 9pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 9pt\">import-csv<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: blueviolet\">c:\\temp\\customers.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">@&#8221;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">Id,Name,Price<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">1,Apple,10<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">2,Orange,12<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">3,Kiwi,15<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;@<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">&gt;<\/span> <span style=\"color: blueviolet\">c:\\temp\\products.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$products<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 9pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 9pt\">import-csv<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: blueviolet\">c:\\temp\\products.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">@&#8221;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">Id,Date,CustomerId<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">1,6\/6\/2012 9:12:44 AM,1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">2,6\/7\/2012 6:12:10 PM,1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">3,6\/5\/2012 12:05:03 PM,2<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;@<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">&gt;<\/span> <span style=\"color: blueviolet\">c:\\temp\\orders.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$orders<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 9pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 9pt\">import-csv<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: blueviolet\">c:\\temp\\orders.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">@&#8221;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">Id,Quantity,ProductId,OrderId<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">1,2,1,1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">2,1,2,1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">3,4,3,1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">4,5,1,2<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">5,4,2,2<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">6,1,1,3<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;@<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">&gt;<\/span> <span style=\"color: blueviolet\">c:\\temp\\orderItems.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$orderItems<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 9pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 9pt\">import-csv<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: blueviolet\">c:\\temp\\orderItems.csv<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;Customers &#8220;<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\">;<span style=\"color: orangered\">$customers<\/span> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span> <span style=\"color: navy\">-AutoSize<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;`r`nProducts &#8220;<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\">;<span style=\"color: orangered\">$products<\/span> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span> <span style=\"color: navy\">-AutoSize<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;`r`nOrders &#8220;<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\">;<span style=\"color: orangered\">$orders<\/span> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span> <span style=\"color: navy\">-AutoSize<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkred;font-family: 'Lucida Console';font-size: 9pt\">&#8220;`r`nOrder Items &#8220;<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\">;<span style=\"color: orangered\">$orderItems<\/span> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span> <span style=\"color: navy\">-AutoSize <\/span><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">Here is the output:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Customers <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Id Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Phone <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">1&nbsp; John Smith&nbsp; (206)555-8899<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">2&nbsp; Mark Stone&nbsp; (425)999-8811<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">3&nbsp; Ruth Moore&nbsp; (425)888-3355<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Products <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Id Name&nbsp;&nbsp;&nbsp; Price<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212; &#8212;-&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">1&nbsp; Apple&nbsp;&nbsp; 10 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">2&nbsp; Orange&nbsp; 12 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">3&nbsp; Kiwi&nbsp;&nbsp;&nbsp; 15 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Orders <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Id Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomerId<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">1&nbsp; 6\/6\/2012&nbsp; 9:12:44 AM 1 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">2&nbsp; 6\/7\/2012&nbsp; 6:12:10 PM 1 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">3&nbsp; 6\/5\/2012&nbsp; 12:05:03 PM 2 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Order Items <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Id Quantity ProductId OrderId<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212; &#8212;&#8212;&#8211; &#8212;&#8212;&#8212; &#8212;&#8212;-<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">1&nbsp; 2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;1 &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 1 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">2&nbsp; 1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 1 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">3&nbsp; 4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;1 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">4&nbsp; 5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;1&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;2 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">5&nbsp; 4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;2&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">6&nbsp; 1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;1&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;3 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;line-height: normal;background: #012456\"><span style=\"font-size: 9.0pt;font-family: 'Lucida Console';color: whitesmoke\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">The equivalent joins in PowerShell with the help of <a href=\"http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2012\/07\/13\/join-object.aspx\">Join-Object<\/a> are as follows:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># Joins the customer to his orders and places Name(from Customer),<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># Date(from Order) and Id (from Order)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerOrders<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 8pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 8pt\">Join-Object<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: navy\">-Left<\/span> <span style=\"color: orangered\">$customers<\/span> <span style=\"color: navy\">-Right<\/span> <span style=\"color: orangered\">$orders<\/span> <span style=\"color: navy\">-LeftProperties<\/span> <span style=\"color: blueviolet\">Name<\/span> <span style=\"color: navy\">-RightProperties<\/span> <span style=\"color: blueviolet\">Date<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Id<\/span> <span style=\"color: navy\">-Where<\/span> {<span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>Id <span style=\"color: darkgray\">-eq<\/span> <span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>CustomerId}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># Adds the OrderItems to the data already gathered. The output objects will<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># have Name(from Customer), Date(from Order), Quantity(from OrderItem) <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># and ProductId (from OrderItem).<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerOrderItems<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 8pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 8pt\">Join-Object<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: navy\">-Left<\/span> <span style=\"color: orangered\">$customerOrders<\/span> <span style=\"color: navy\">-Right<\/span> <span style=\"color: orangered\">$orderItems<\/span> <span style=\"color: navy\">-LeftProperties<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Date<\/span> <span style=\"color: navy\">-RightProperties<\/span> <span style=\"color: blueviolet\">Quantity<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">ProductId<\/span> <span style=\"color: navy\">-Where<\/span> {<span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>Id <span style=\"color: darkgray\">-eq<\/span> <span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>OrderId}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># Adds the Products to the data already gathered. The output objects will<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># have Name (from Customer), Date(from Order), Quantity (from OrderItem)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># Product Name (from Product) and Price from Product<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># We use a Hashtable instead of simply &#8220;Name&#8221; for Product Name because<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># &#8220;Name&#8221; is already present in the output object for the customer name,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># so we need to differentiate the Product name from that.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># If you did not know the syntax for the Hashtable Expression, you will<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: darkgreen;font-family: 'Lucida Console';font-size: 8pt\"># be interested in the fact it also works for Select-Object properties<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerProducts<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 8pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 8pt\">Join-Object<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: navy\">-Left<\/span> <span style=\"color: orangered\">$customerOrderItems<\/span> <span style=\"color: navy\">-Right<\/span> <span style=\"color: orangered\">$products<\/span> <span style=\"color: navy\">-LeftProperties<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Date<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Quantity<\/span> <span style=\"color: navy\">-RightProperties<\/span> @{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8220;Product Name&#8221;<\/span>;Expression<span style=\"color: darkgray\">=<\/span>{<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Name}}<span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Price<\/span> <span style=\"color: navy\">-Where<\/span> {<span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>ProductId <span style=\"color: darkgray\">-eq<\/span> <span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>Id}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerProducts<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table <\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: blue;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\">Here is the output:<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quantity Product Name Price<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212; &#8212;&#8211;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">John Smith 6\/6\/2012 9:12:44 AM&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">John Smith 6\/6\/2012 9:12:44 AM&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Orange&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">John Smith 6\/6\/2012 9:12:44 AM&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kiwi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">John Smith 6\/7\/2012 6:12:10 PM&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">John Smith 6\/7\/2012 6:12:10 PM&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Orange&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Mark Stone 6\/5\/2012 12:05:03 PM 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">So, the following three lines of code &hellip;<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerOrders<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 8pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 8pt\">Join-Object<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: navy\">-Left<\/span> <span style=\"color: orangered\">$customers<\/span> <span style=\"color: navy\">-Right<\/span> <span style=\"color: orangered\">$orders<\/span> <span style=\"color: navy\">-LeftProperties<\/span> <span style=\"color: blueviolet\">Name<\/span> <span style=\"color: navy\">-RightProperties<\/span> <span style=\"color: blueviolet\">Date<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Id<\/span> <span style=\"color: navy\">-Where<\/span> {<span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>Id <span style=\"color: darkgray\">-eq<\/span> <span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>CustomerId}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerOrderItems<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 8pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 8pt\">Join-Object<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: navy\">-Left<\/span> <span style=\"color: orangered\">$customerOrders<\/span> <span style=\"color: navy\">-Right<\/span> <span style=\"color: orangered\">$orderItems<\/span> <span style=\"color: navy\">-LeftProperties<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Date<\/span> <span style=\"color: navy\">-RightProperties<\/span> <span style=\"color: blueviolet\">Quantity<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">ProductId<\/span> <span style=\"color: navy\">-Where<\/span> {<span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>Id <span style=\"color: darkgray\">-eq<\/span> <span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>OrderId}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 8pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 8pt\">$customerProducts<\/span><span style=\"color: darkgray;font-family: 'Lucida Console';font-size: 8pt\">=<\/span><span style=\"color: blue;font-family: 'Lucida Console';font-size: 8pt\">Join-Object<\/span><span style=\"font-family: 'Lucida Console';font-size: 8pt\"> <span style=\"color: navy\">-Left<\/span> <span style=\"color: orangered\">$customerOrderItems<\/span> <span style=\"color: navy\">-Right<\/span> <span style=\"color: orangered\">$products<\/span> <span style=\"color: navy\">-LeftProperties<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Date<\/span><span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Quantity<\/span> <span style=\"color: navy\">-RightProperties<\/span> @{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8220;Product Name&#8221;<\/span>;Expression<span style=\"color: darkgray\">=<\/span>{<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Name}}<span style=\"color: darkgray\">,<\/span><span style=\"color: blueviolet\">Price<\/span> <span style=\"color: navy\">-Where<\/span> {<span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>ProductId <span style=\"color: darkgray\">-eq<\/span> <span style=\"color: orangered\">$args<\/span><span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>Id}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&hellip; do the same job as the SQL statement:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">SELECT&nbsp;&nbsp;&nbsp;Customer.Name, [Order].Date, OrderItem.Quantity,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.Name AS [Product Name], Product.Price<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN Product ON OrderItem.ProductId = Product.id INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Customer INNER JOIN&nbsp; [Order] ON Customer.id = [Order].CustomerId ON OrderItem.OrderId = [Order].id<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: justify\">There are some advantages to the SQL statement:<\/p>\n<p class=\"MsoListParagraphCxSpFirst\" style=\"margin: 0pt;padding: 0pt;text-align: justify;text-indent: -0.25in\"><span style=\"font-family: Symbol\">&middot;<span style=\"font: 7pt\/normal 'Times New Roman'\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span>It is a single statement that is somewhat shorter than the three statements&nbsp; in PowerShell.<\/p>\n<p class=\"MsoListParagraphCxSpLast\" style=\"margin: 0pt;padding: 0pt;text-align: justify;text-indent: -0.25in\"><span style=\"font-family: Symbol\">&middot;<span style=\"font: 7pt\/normal 'Times New Roman'\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span>It has a better syntax for aliasing a property in the output (&ldquo;as ProductName&rdquo; as opposed to &ldquo;<span style=\"line-height: 115%;font-family: 'Lucida Console';font-size: 9pt\">@{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8220;Product Name&#8221;<\/span>;Expression<span style=\"color: darkgray\">=<\/span>{<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Name}}<\/span>&rdquo;).<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">In my opinion, those are small advantages. Each one of the PowerShell join statements is easy to understand in isolation. The hashtable syntax used in the third command (to change a property name) is a bit long, but very common to PowerShell users, because&nbsp; it is useful for other cmdlets including Select-Object.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">I considered changing Join-Object to take all the lists and Where clauses in a single cmdlet call, but the need to pair each of two lists with a Where clause (and a Join type) makes the command a bit too cryptic for my taste. I prefer three statements that are easy to understand to one that is not. Performance-wise, there is no difference, because each Join has to be considered in isolation.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Now that the data is joined, what about getting the total money spent by each customer, the total money spent in each product and the total money spent?<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\"><b>Total Money Spent by Each Customer<\/b><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\">Let&rsquo;s start with the whole command:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$customerProducts<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">name<\/span> <span style=\"color: darkgray\">|<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Select-Object<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span>@{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8216;Total&#8217;<\/span>;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression<span style=\"color: darkgray\">=<\/span>{<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Group <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">ForEach-Object<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Begin<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">=<\/span><span style=\"color: purple\">0<\/span>;} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Process<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">+=[<\/span><span style=\"color: teal\">int<\/span><span style=\"color: darkgray\">]<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Price<span style=\"color: darkgray\">*<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Quantity} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-End<\/span> {<span style=\"color: orangered\">$total<\/span>}}} <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span>&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">It produces this output:<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sum<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">John Smith 190<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">Mark Stone&nbsp; 10<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The first line:<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\"><span style=\"color: orangered;line-height: 115%;font-family: 'Lucida Console';font-size: 9pt\">$customerProducts<\/span><span style=\"line-height: 115%;font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">name<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Produces two groups:<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">Count Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">&nbsp;&nbsp;&nbsp; 5 John Smith&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=John Smith; Date=6\/6\/2012 9:12:44 AM;&#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: courier new,courier;font-size: 9pt\">&nbsp;&nbsp;&nbsp; 1 Mark Stone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=Mark Stone; Date=6\/5\/2012 12:05:03 PM;&#8230;&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">In order to better see what is in each group, we run:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">(<span style=\"color: orangered\">$customerProducts<\/span> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">name<\/span>)<span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">0<\/span><span style=\"color: darkgray\">].<\/span>Group <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Which produces:<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6\/6\/2012 9:12:44 AM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Quantity&nbsp;&nbsp;&nbsp; : 2<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">ProductName : Apple<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Price&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;: 10<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6\/6\/2012 9:12:44 AM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Quantity&nbsp;&nbsp;&nbsp; : 1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">ProductName : Orange<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 12<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6\/6\/2012 9:12:44 AM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Quantity&nbsp;&nbsp;&nbsp; : 4<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">ProductName : Kiwi<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 15<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6\/7\/2012 6:12:10 PM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Quantity&nbsp;&nbsp;&nbsp; : 5<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">ProductName : Apple<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 10<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6\/7\/2012 6:12:10 PM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Quantity&nbsp;&nbsp;&nbsp; : 4<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">ProductName : Orange<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 12 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">And:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">(<span style=\"color: orangered\">$customerProducts<\/span> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">name<\/span>)<span style=\"color: darkgray\">[<\/span><span style=\"color: purple\">1<\/span><span style=\"color: darkgray\">].<\/span>Group <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Which produces:<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Mark Stone<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6\/5\/2012 12:05:03 PM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Quantity&nbsp;&nbsp;&nbsp; : 1<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">ProductName : Apple<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 10 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">So, inside the &ldquo;Group&rdquo; property of each object in the output of group-object is the Price and Quantity we want to multiply in order to get a total. If we wanted just the total quantity of fruit we could do:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$customerProducts<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">name<\/span> <span style=\"color: darkgray\">|<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Select-Object<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp; @{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8216;Total&#8217;<\/span>;Expression<span style=\"color: darkgray\">=<\/span>{(<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Group <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Measure-Object<\/span> <span style=\"color: blueviolet\">Quantity<\/span> <span style=\"color: navy\">-Sum<\/span>)<span style=\"color: darkgray\">.<\/span>Sum}} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span>&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">With output:<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Total<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">John Smith&nbsp;&nbsp;&nbsp; 16<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Mark Stone&nbsp;&nbsp;&nbsp;&nbsp; 1 <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: blueviolet;font-family: 'Lucida Console'\">Name<\/span> is the first column in the output. The second column is given by:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">@{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8216;Total&#8217;<\/span>; Expression<span style=\"color: darkgray\">=<\/span>{(<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Group <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Measure-Object<\/span> <span style=\"color: blueviolet\">Quantity<\/span> <span style=\"color: navy\">-Sum<\/span>)<span style=\"color: darkgray\">.<\/span>Sum}}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">This hashtable is a syntax for select object which means a column with a Name = Total and a value which is the Expression. The Expression gets the value of the Group property and pipes to Measure-Object to sum the &lsquo;Quantity&rsquo; property of each member of the Group. Finally the Sum property of the Measure-Object result is retrieved. That property contains the actual sum.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Since we want to get Price * Quantity and measure-object only supports plain properties we end up with the full command repeated here:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$customerProducts<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">name<\/span> <span style=\"color: darkgray\">|<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Select-Object<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span>@{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8216;Total&#8217;<\/span>;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression<span style=\"color: darkgray\">=<\/span>{<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Group <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">ForEach-Object<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Begin<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">=<\/span><span style=\"color: purple\">0<\/span>;} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Process<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">+=[<\/span><span style=\"color: teal\">int<\/span><span style=\"color: darkgray\">]<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Price<span style=\"color: darkgray\">*<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Quantity} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-End<\/span> {<span style=\"color: orangered\">$total<\/span>}}} <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span>&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Instead of | measure-object we have a | ForEach-Object where we use &ndash;Begin, -Process and &ndash;End to evaluate the total. This could be easily modified to calculate anything else, including averages, standard deviations, etc.<\/p>\n<p class=\"MsoNormal\"><span style=\"line-height: 115%;font-size: 4pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt;text-align: justify\">Note: The [int] cast in front of $_.Price is required because the price is a string out of our CSV file. This could be avoided by using Export-CliXml and Import-CliXml for our data, whioch would preserve the data type.<\/p>\n<p class=\"MsoListParagraph\" style=\"text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">Here is the corresponding SQL statement:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">SELECT&nbsp;&nbsp;&nbsp;Customer.Name, <b>SUM(OrderItem.Quantity * Product.Price)<\/b> AS SUM<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product ON OrderItem.ProductId = Product.id INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Customer INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Order] ON Customer.id = [Order].CustomerId ON OrderItem.OrderId = [Order].id<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\"><b>GROUP BY Customer.Name<\/b><\/span><\/p>\n<p class=\"MsoNormal\"><b>&nbsp;<\/b><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The SQL statement combines the joining, grouping and total evaluation(Price * Quantity) operations.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The Powershell statement is only doing the grouping and total evaluation, since the $customerProducts variable has the result of the joins performed in the previous section of this blog post.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The bold segments of the SQL statement are performing the grouping and the PowerShell statement.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">SQL is designed specifically for this kind of data, so it provides a shorter syntax overall, but I believe the PowerShell equivalent is simple enough to understand.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\"><b>Total Money Spent in Each Product<\/b><\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify\">The only thing that changes from the previous section is that the property we&rsquo;re passing to Group-Object is &ldquo;ProductName&rdquo;:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$customerProducts<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">Group-Object<\/span> <span style=\"color: blueviolet\">ProductName<\/span> <span style=\"color: darkgray\">|<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Select-Object<\/span> <span style=\"color: blueviolet\">Name<\/span><span style=\"color: darkgray\">,<\/span>@{Name<span style=\"color: darkgray\">=<\/span><span style=\"color: darkred\">&#8216;Total&#8217;<\/span>;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression<span style=\"color: darkgray\">=<\/span>{<span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Group <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">ForEach-Object<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Begin<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">=<\/span><span style=\"color: purple\">0<\/span>;} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Process<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">+=[<\/span><span style=\"color: teal\">int<\/span><span style=\"color: darkgray\">]<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Price<span style=\"color: darkgray\">*<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Quantity} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-End<\/span> {<span style=\"color: orangered\">$total<\/span>}}} <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">format-table<\/span>&nbsp;&nbsp; <\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Name&nbsp;&nbsp; Sum<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">&#8212;-&nbsp;&nbsp; &#8212;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Apple&nbsp;&nbsp; 80<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Orange&nbsp; 60<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: #012456;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: whitesmoke;font-family: 'Lucida Console';font-size: 9pt\">Kiwi&nbsp;&nbsp;&nbsp; 60 <\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">The corresponding SQL is:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">SELECT&nbsp;&nbsp;Product.Name, <b>SUM(OrderItem.Quantity * Product.Price)<\/b> AS Sum<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">FROM&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product ON OrderItem.ProductId = Product.id<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\"><b>GROUP BY Product.Name<\/b><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\"><b>Total Money Spent<\/b><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\">Here is the command that produces this total:<\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"color: orangered;font-family: 'Lucida Console';font-size: 9pt\">$customerProducts<\/span><span style=\"font-family: 'Lucida Console';font-size: 9pt\"> <span style=\"color: darkgray\">|<\/span> <span style=\"color: blue\">ForEach-Object<\/span> `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Begin<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">=<\/span><span style=\"color: purple\">0<\/span>;} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-Process<\/span> {<span style=\"color: orangered\">$total<\/span><span style=\"color: darkgray\">+=[<\/span><span style=\"color: teal\">int<\/span><span style=\"color: darkgray\">]<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Price<span style=\"color: darkgray\">*<\/span><span style=\"color: orangered\">$_<\/span><span style=\"color: darkgray\">.<\/span>Quantity} `<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: navy\">-End<\/span> {<span style=\"color: orangered\">$total<\/span>}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"background: white;margin: 0pt;padding: 0pt;line-height: normal\"><span style=\"font-family: 'Lucida Console';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">Here is the corresponding SQL:<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">SELECT&nbsp; <b>SUM(OrderItem.Quantity * Product.Price)<\/b> AS Sum<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">FROM&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\"><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product ON OrderItem.ProductId = Product.id<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"margin: 0pt;padding: 0pt\">Lucio Silveira[MSFT]<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Joining Multiple Tables, Grouping And Evaluating Totals This is a continuation to the Join-Object blog post considering multiple joins and SQL style grouping and total evaluation. Problem: In the Join-Object blog we&rsquo;ve seen that relational data naturally organizes in multiple tables.&nbsp;Once we have those tables, we frequently want to see&nbsp;the information back together, so we [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Joining Multiple Tables, Grouping And Evaluating Totals This is a continuation to the Join-Object blog post considering multiple joins and SQL style grouping and total evaluation. Problem: In the Join-Object blog we&rsquo;ve seen that relational data naturally organizes in multiple tables.&nbsp;Once we have those tables, we frequently want to see&nbsp;the information back together, so we [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=2191"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=2191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=2191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=2191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}