0

Suppose My Database is like this :

MemberName  MemberID   ResultsEligibilityID
Thuso         2              1
Thuso         2              1
Maubane       3              2
Maubane       3              1
CDeveloper    5              2
CDeveloper    5              2

Now is it possible to write a query to display (The Below output) based on this:

if both ResultsEligibilityID for a single Member is 1 then Eligibile, Otherwise Non-Eligible.

OUTPUT

MemberName  MemberID  ResultsEligibilityID  Results
Thuso        2              1             Eligible
Maubane      3              2             Non-Eligible
CDeveloper   5              2             Non-Eligible

Thanks in advance for the help.

1
  • 1
    I would group by using MAX eligibility and a CASE statement for the Results column. CASE MAX(EligibilityID)=1 then 'Eligible' Else 'Non' End Commented Nov 1, 2013 at 12:07

1 Answer 1

3

Please try:

select 
    MemberName,
    MemberID, 
    MAX(ResultsEligibilityID) ResultsEligibilityID ,
    (case when sum(case when ResultsEligibilityID=1 then 1 else 0 end)= COUNT(*) 
    then 'Eligible' else 'Non-Eligible' end) Results
From 
    YourTable
group by MemberName,MemberID
Sign up to request clarification or add additional context in comments.

2 Comments

Why take a sum, if max>1 then not eligible?
great stuff :-) Thanks a lot Daniel and Techdo

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.