Reputation: 93
I have a student table.
Student_Name Ethnicity1 Ethnicity2
============ ========== ===========
A Asian NZ European
B Indian Asian
C NZ European
I want to write a SQL statement where I want to group them into two ethnicities only - Asian / non-Asian. I don't want to use the where clause. So I have 700 students and I want to see the third column, where if the student's first ethnicity or second ethnicity is Asian then the third column should say Asian. something like this
Student_Name Ethnicity1 Ethnicity2 Ethnicity
=========== ========== ========== ========
A Asian NZ European Asian
B Indian Asian Asian
C NZ European Non-Asian
Could anyone help, please?
Upvotes: 0
Views: 51
Reputation: 1269693
Based on your logic you specify:
select t.*,
(case when 'Asian' in (ethnicity1, ethnicity2) then 'Asian'
else 'Non-Asian'
end) as simplified_ethnicity
Upvotes: 1
Reputation: 86
Its rather a simple case statement, any how, if i understood ur question query might be
Select T.*, Case When T.Ethnicty1 In ('Asian', 'India') or T.Ethnicty2 In ('Asian', 'India') Then 'Asian' Else 'Non-Asian' End EthnicCity From Students T
Upvotes: 0