0

假设我的数据库是这样的:

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

现在是否可以基于此编写查询以显示(以下输出):

如果单个会员的两个 ResultsEligibilityID 均为 1,则为合格,否则为不合格。

输出

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

在此先感谢您的帮助。

4

1 回答 1

3

请试试:

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
于 2013-11-01T12:08:41.010 回答