Add a column according to the field condition
There is a table student that has the following structure:
Sid sname ssex = 1 Zhang San 1 2 Li Si 1 3 Liu Hong 0 4 Yang Jing 0 5 Li Xing 1
The requirement to write a sql statement shows the following effect:
Sid sname ssex gender = 1 Zhang San 1 male 2 Li Si 1 male 3 Liu Hong 0 female 4 Yang Jing 0 female 5 Li Xing and 1 male
Solution:
Select case when column > 'condition value' then 'value 1' else 'value 2' end from table
That is:
Select *, case when ssex=1 then 'male' else 'female' end as' gender 'from student