0

i cant quite figure out how to put this into a simple question, so I'll explain what I have and what I need to do.

Table A

|..ItemNum..|..ItemUse..|..SubC..|..MainC..|

|..123..|..B..|..AAA..|..QQQ..|

|..456..|..J..|..BBB..|..QQQ..|

|..123..|..D..|..DDD..|..RRR..|

|..789..|..C..|..CCC..|..WWW..|

|..345..|..W..|..EEE..|..TTT..|

|..678..|..B..|..FFF..|..YYY..|

I need to make a list of ItemNum and MainC that are grouped into 3 categories:

B / C / D = 1 <anything else> = 2 B / C / D & <anything else> = 3 

So my results would be:

|..MainC..|..Group..|

|..QQQ..|..3..|

|..RRR..|..1..|

|..WWW..|..1..|

|..TTT..|..2..|

|..YYY..|..1..|

I've got an iif setup that takes care of groups 1 and 2, but cant figure out how to get the values in MainC to come out with Group 3.

Any ideas?

1
  • What kind of database are you using? Commented Jun 5, 2014 at 16:58

1 Answer 1

0

I don't understand your explanation ( especially the mapping to 3 ) but here's a shot:

select MainC, case when ItemUse in ('B','C','D') then 1 else 2 end as group from A 
Sign up to request clarification or add additional context in comments.

1 Comment

ItemUse represents different usage class of MainC (usually an app). If ItemUse is B,C, or D the MainC is group1. If its anything else, say E or T, then the MainC is group 2. SubC represents some specific component of it's MainC, hence QQQ having 2 lines. If a MainC has only 1 SubC then it can only in groups 1 or 2, but if has multiple SubC's it could fall into group 3, meaning that MainC functions in both group 1 and group 2. I can get the ones in groups 1&2, but I can't figure out how to test if a MainC falls into Group3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.