我如何使用 select 为 table 填充具有特定固定值的列
How do i fill a column with specific fixed value for a table using select
我想要 select 一些数据,但该数据有一个包含 NULL
值的列。我希望它在不更改数据库的情况下将其从 null 更改为特定的固定值
即
V_fruits
number | fruit | three
1 | apple | <null>
2 | pinapple | <null>
3 | grape | <null>
4 | lemon | <null>
我想要使用
Select "number","fruit",case when "three" is null then three='ofcourse' from V_fruits
我需要一些指导,请 Psql
预计
V_fruits
number fruit three
1 apple Of course
2 pinapple Of course
3 grape Of course
4 lemon Of course
获得
V_fruits
number fruit three
1 apple false
2 pinapple false
3 grape false
4 lemon false
改为:
Select "number","fruit",case when "three" is null then 'ofcourse' END from V_fruits
这里的区别在于three='ofcourse'
和returns false
因为three
是空的,所以它不能是'ofcourse'
。
您可以选择使用:
SELECT "number", "fruit", COALESCE(three, 'ofcourse') FROM v_fruits;
我想要 select 一些数据,但该数据有一个包含 NULL
值的列。我希望它在不更改数据库的情况下将其从 null 更改为特定的固定值
即 V_fruits
number | fruit | three
1 | apple | <null>
2 | pinapple | <null>
3 | grape | <null>
4 | lemon | <null>
我想要使用
Select "number","fruit",case when "three" is null then three='ofcourse' from V_fruits
我需要一些指导,请 Psql
预计 V_fruits
number fruit three
1 apple Of course
2 pinapple Of course
3 grape Of course
4 lemon Of course
获得 V_fruits
number fruit three
1 apple false
2 pinapple false
3 grape false
4 lemon false
改为:
Select "number","fruit",case when "three" is null then 'ofcourse' END from V_fruits
这里的区别在于three='ofcourse'
和returns false
因为three
是空的,所以它不能是'ofcourse'
。
您可以选择使用:
SELECT "number", "fruit", COALESCE(three, 'ofcourse') FROM v_fruits;