Open hchaggar opened 6 years ago
with cte as ( select count(distinct customerid) as count_of_customers_ordered ,eomonth(soh.orderdate) as ordermonth from sales.SalesOrderHeader soh inner join sales.salesorderdetail sod on sod.SalesOrderID = soh.SalesOrderID inner join production.product p on sod.ProductID = p.ProductID where isnull(p.color, 'missing') in ('red', 'black', 'missing', 'blue', 'silver') group by eomonth(soh.orderdate) )
--test code / 1216 2005 3094 2006 9864 2007 11844 2008 / select sum(count_of_customers_ordered) ,year(ordermonth) from cte group by year(ordermonth)
blah blah blah