Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Add a column according to the field condition

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report