-3

我正在尝试选择符合这些条件的行

    IF kid=IND and kid=Family 
       then select Kid=IND 

    If kid only has Family 
       then select family. 

    if kid only has IND 
       then select IND.      

我将如何使用 CASE 执行此操作?

前任。

kid_id   date       type

001      1/1/2013   IND
001      1/1/2013   Family
002      1/2/2013   Family
003      1/3/2013   IND

结果

001   1/1/2013   IND
002   1/2/2013   Family
003   1/3/2013   IND 
4

1 回答 1

0
select 
case 
When (kid=ind and kid=family) Then ind
When kid=family then family
When kid=ind then ind
else
  null
end

From SomeTable

给定kid、ind 和family 是表中的列。

你的意思是这样的吗

select kid_id,date, 
case 
When (kid=ind and kid=family) Then 'Both'
When kid=family then family
When kid=ind then ind
else
  'None'
end as TypeGroup

From SomeTable
于 2013-05-23T13:36:42.407 回答