Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 805515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:05:33+00:00 2026-05-15T00:05:33+00:00

I have a table of sales data for example: SELECT ItemCode, ItemDesc, TotalYearlySales, ShareOfBusiness,

  • 0

I have a table of sales data for example:

SELECT ItemCode, ItemDesc, TotalYearlySales, ShareOfBusiness, ABCIndicator
FROM Sales
WHERE Yir = Year(getdate())
AND Manth = Month(getdate())
ORDER BY TotalYearlySales DESC

The ShareOfBusiness is computed as the Item’s (TotalYearlySales/SUM(TotalYearlySales))*100

The ABCIndicator is A for the list of items whose sum is 80% of the SUM(ShareOfBusiness). B for the next 15% and C for the last 5%.

How can I get the ABCIndicator for each item?

Sample Data:

ItemCode ItemDesc      TotalYearlySales ShareOfBusiness ABCIndicator
1234     Yellow Flute  3000             .36             A
1235     Brown Violin  2000             .24             A
1236     Silver Flute  1800             .21             A
1236     Pink Drums    1500             .18             B
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:05:34+00:00Added an answer on May 15, 2026 at 12:05 am

    You could compute the sum and the running sum in a subquery. The running sum is the total amount of sales for that row and rows with a higher sum.

    select
        ItemCode
    ,   ItemDesc
    ,   TotalYearlySales
    ,   TotalYearlySales / SalesSum as Share
    ,   case when RunningSum > 0.2 * SalesSum then 'A'
             when RunningSum > 0.05 * SalesSum then 'B'
             else 'C'
        end as ABCIndicator    
    from (
        select
            ItemCode
        ,   ItemDesc
        ,   TotalYearlySales
        ,   (
            select sum(TotalYearlySales) 
            from @Sales t1
            where Yir = Year(getdate())
            ) as SalesSum
        ,   (
            select sum(TotalYearlySales) 
            from @Sales t2
            where Yir = Year(getdate()) 
                  and TotalYearlySales <= t3.TotalYearlySales
            ) as RunningSum
        from @Sales t3
        where Yir = Year(getdate())
    ) sub
    

    This prints:

    ItemCode  ItemDesc      TotalYearlySales  Share  ABCIndicator
    1234      Yellow Flute  3000              0,36   A
    1235      Brown Violin  2000              0,24   A
    1236      Silver Flute  1800              0,21   A
    1236      Pink Drums    1500              0,18   B
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with sales per store as follows: SQL> select * from
Let's say I have a table: SELECT SUM(quantity) AS items_sold_since_date, product_ID FROM Sales WHERE
I have the following example in a SQL table Cust Group Sales A 1
OK I have created a product table [ID, itemCode], a sales table and a
I have one table that has sales records and another table that has additional
I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
I need a little help brainstorming on a query. I have a sales table
I have an SQL table like this : sales(product,timestamp) I want to display a
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I have the following SQL table - Date StoreNo Sales 23/4 34 4323.00 23/4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.