如何在单个sql查询中替换两个字符串或整数记录 [英] How to replace two string or integers records in single sql query

查看:161
本文介绍了如何在单个sql查询中替换两个字符串或整数记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你能回答我对下表的疑问。



例如我有一张下表设计



eid性别

1 M

2 F

3 M

4 F



在单个SQL查询中,我想将字符串M替换为MALE,将F替换为FEMALE的性别列。

I would like you to kindly answer me the query for the below table.

For eg i have a table in the below design

eid Gender
1 M
2 F
3 M
4 F

In a single sql query i want to replace the string M as 'MALE' and F as 'FEMALE'in gender column.

推荐答案

你可以使用这个查询,



You can use this query,

update yourtablename
set gender=case WHEN gender= 'm' THEN 'male'
  WHEN val = 'f' THEN 'female'  end


UPDATE tblGender SET Gender = CASE WHEN Gendor ='M' THEN 'Male' ELSE 'Female' END


这篇关于如何在单个sql查询中替换两个字符串或整数记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆