SQL Server: Group similar sales together

ibanez2

New Member
I'm trying to do some reporting in SQL Server.Here's the basic table setup: \[quote\] Order (ID, DateCreated, Status) Product(ID, Name, Price) Order_Product_Mapping(OrderID, ProductID, Quantity, Price, DateOrdered)\[/quote\]Here I want to create a report to group product with similar amount of sales over a time period like this:Sales over 1 month:\[quote\] [*]Coca, Pepsi, Tiger: $20000 average(coca:$21000, pepsi: $19000, tiger: $20000) [*]Bread, Meat: $10000 avg (bread:$11000, meat: $9000) \[/quote\]Note that the text in () is just to clarify, not need in the report). User define the varying between sales that can consider similar. Example sales with varying lower than 5% are consider similar and should be group together. The time period is also user defined.I can calculate total sale over a period but has no ideas on how to group them together by sales varying. I'm using SQL Server 2012. Any help is appreciated.Sorry, my English is not very good :)
 
Top