Home > database >  SQL to add the column content
SQL to add the column content

Time:11-01

Such as the select aa from bb
Aa display for 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 I now want to convert into other content such as hydrogen, helium, lithium beryllium boron how should do

CodePudding user response:

The
refer to the original poster Wang Huixiang response:
such as the select aa from bb
Aa display for 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 I now want to convert into other content such as hydrogen, helium, lithium beryllium boron should do

Add another column content for day day day day day, cannot use the alter table

CodePudding user response:

The case when

CodePudding user response:

 
-- -- -- -- -- the first way
Select the Replace (Replace (aa, '1', 'h'), '2', 'helium) as aa from bb

- the second option
The select (case when aa='1' then 'h' else 'end + case when aa=' 2 'then' helium 'else' end) as aa from bb
- the third way

CodePudding user response:

The
refer to the original poster Wang Huixiang response:
such as the select aa from bb
Aa display for 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 I now want to convert into other content such as hydrogen, helium, lithium beryllium boron should do


1, in case the when, such as
3 floor2, using a temporary table join
3, use a custom function
4, with the string location, for example: select substring (' hydrogen, helium lithium beryllium, boron, 3, 1)
  • Related