tsql - How to Compute for ABCIndicator in T-SQL -


I have a table of sales data for example:

  select ItemCode , ItemDesc, TotalYearlySales, Seyrof Business, ABC indicator from Sales Yir = year (dot credit ()) and Month = Month (Dotdet ()) Total Wi-Day orders by sales Diissi  

Seyrof Business item Total annual sales / Syuem (total annual sales) * 100

ABC indicator has 80% of whose amount SM (Seyrof Business) Yes. B. The next 15% and the last 5% for C.

How do I get ABCIdicator for each item?

Sample data:

  Aitmkod item Dasek total weekly sales Seyrof Business ABC Indicator 1234 Yellow Flute 3000 36 A 1235 Brown violin 2000 .24 A 1236 Silver Bant 1800 21 A 1236 pink drum 1500.18b  
class = "post-text" itemprop = "text">

You can add yoga in a subquery and run totals The calculation of the current amount is the total amount of sales for that line and rows with the higher amount.

  ItemCode, Maddisk, Total Year Sales, Total Year Sales / Sales As Sale, Case When RunningSam & gt; 0.2 * Sales is back then 'A' when RunningSam & gt; 0.05 * As ABC indicator as Selssm 'B' A 'C' ABC (Aitmkod, Item Daisek, select the total annual sales (total sales) @ Sales t 1, where Yir = year (dot credit ())) as Selssm, total sales sales) @ sales T2 where Yir = year (dot credit ()) and total doubles sales and LT as Running Sum @ sales T3, where Yir = year ( Dot Dit ())) Sub  

Print:

  ItemCode I Tmdisk total annual Silent stock ABC Indicator 1234 Yellow instruments 3000 0,36 A 1235 Brown violin 2000 0,24 A 1236 Silver Flute 1800 0.21 A 1236 pink drum 1500 0 18 B  

Comments