This is on MSSQL/Azure SQL.
I have the following Sales Table:
I am trying to get an output that shows for each SKU, the total number of Orders (very easy) AND the total number of line items for an Order that contains that SKU.
So for the first part:
select SKU, count(distinct(sales_order_id) as "Order_Count" from Table T group by SKU
Easy enough, however the second part is doing my head in -
The desired output would look like this:
How do I get a count of the total Line_item_IDs for each order that contains a SKU? Ideally in a single query without a load of crazy joins or subqueries.