开发者

SQL change value

开发者 https://www.devze.com 2023-04-03 06:36 出处:网络
I\'m trying to do a select query where I\'m trying to change the value. select * from config where category = \'basic\'

I'm trying to do a select query where I'm trying to change the value.

select * from config where category = 'basic'

For example I would like that the output shows 'general' instead of 'basic'. But I don't want to update all the 'basic' value's into 'general'

Is there开发者_C百科 a way to do this?


Try this:

SELECT field1, field2, ...,
  CASE 
    WHEN category = 'basic' THEN 'general'
    ELSE category
  END
FROM config

or, in this particular case:

SELECT field1, field2, ...., 'general'
FROM config
WHERE category = 'basic'


Make use of Case.. When statement resolve your issue

select 

  case when category = 'basic' then 'general' else category end

 from config


select c.foo, c.bar, 'general' from config c where c.category = 'basic'
0

精彩评论

暂无评论...
验证码 换一张
取 消