calc % from 1 col 1 table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Reden
    New Member
    • Aug 2011
    • 4

    calc % from 1 col 1 table

    Hello,

    I am attempting to figure out market share % for contracted widgets (ie CVRid for contracted = 50 and competitive = 55). All data is in a single table. It needs to grouped by TC where the BKid is the same.

    table 1
    col1 - TC
    col2 - TCid
    col3 - bKid
    col4 - CVRid
    col5 - Units
    col6 - Prod_num

    within any TC is any number of prod_num's that can have a CVRid of either 50 or 55, so I am trying to get..." sum(50/50+55)*100".

    Have tried three different ways and am getting various errors or empty sets. ugh

    Rick
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Could you post some sample data and how you want the result to look like?

    Also, could you post whatever you have so far?


    ~~ CK

    Comment

    • Reden
      New Member
      • Aug 2011
      • 4

      #3
      CK,

      Here is one of the versions. Please notice that a prod_num can be in several TC's.

      Thx,
      Rick

      (select t1.TC,t1.TCid,s um(t1.units))
      from test_db as t1
      join test_db t2 on
      t1.TCid = t2.TCid
      where t1.CVRid = t2.CVRid and t1.BKid = t2.BKid and t1.TCid = t2.TCid
      group by t1.TC

      /
      (select sum(t1.units)
      from test_db as t1
      join test_db t2 on
      t1.TCid = t2.TCid
      where t1.CVRid = t2.CVRid and t1.BKid = t2.BKid and t1.TCid = t2.TCid)


      TC Tcid Bkid CVRid Units prod_num
      TC-A 2 1 50 25 423
      TC-A 2 1 50 20 335
      TC-A 2 1 50 10 112
      TC-A 2 1 55 5 245
      TC-A 2 1 55 20 276
      TC-A 2 1 55 10 275
      TC-B 3 1 55 10 275
      TC-B 3 1 55 20 276
      TC-B 3 1 50 25 300
      TC-B 3 1 50 20 325

      Comment

      • Reden
        New Member
        • Aug 2011
        • 4

        #4
        sorry forgot to add output

        TC-a XX.XX%
        TC-B XX.XX%
        etc.

        Thank you

        Comment

        • Reden
          New Member
          • Aug 2011
          • 4

          #5
          I figured it out, I was making it more difficult than it needed. All Set.

          R

          Comment

          • ck9663
            Recognized Expert Specialist
            • Jun 2007
            • 2878

            #6
            Sorry about the late reply...Can you post what you did so we can share it with everyone?

            Happy Coding!!!


            ~~ CK

            Comment

            Working...