SQLTeam.com | Weblogs | Forums

Total number of Orders,Total amount and AOV

sql2012

#1

I have to get total number of order by customer , total value for all those orders ,average order value and email . where from -to dates and Country I have mentioned in where clause. This is my table. [Sell-to Customer No_] is customer id.

      SELECT 

       [Sell-to Customer No_]
      ,[Bill-to Name]
      ,[Order Date]
      ,[Amount]
     ,[Original Order No_]
     ,[Country]
     ,[Email]
     FROM [TBW_BI].[dbo].[Dreams$Internet Orders]
     WHERE [Country]='RUSSIA' and 
     [order date] >= '2016-11-18T00:00:00.000' AND 
     [order date] <= '2017-04-10T00:00:00.000'

#2

try this

Select [Sell-to Customer No_]
,SUM([Amount])
,COUNT([Original Order No_])
from [TBW_BI].[dbo] . [Dreams$Internet Orders]
WHERE [Country]='RUSSIA' and
[order date] >= '2016-11-18T00:00:00.000' AND
[order date] <= '2017-04-10T00:00:00.000'
group by [Sell-to Customer No_]


#3

Thank you . With that I have tried Avg() function as well. all good.