Home > database >  SQL how to add a new column
SQL how to add a new column

Time:10-14

Postgresql need to add a new column, when customer_type=1 or 2, id is added to the new column customer_id
The original table table roughly as follows:
Id customer_type
111 2
112 1
113
114 2
Results the following
Id customer_type customer_id
111 2 111
112 1 112
113
114 2 114

Help leaders to help write the SQL statement

CodePudding user response:

When I found that you write programs don't like baidu, if I was advertised

CodePudding user response:

Don't need to make what the new column, it is ok to create a view:
 create view view_tablename 
As
Select id
, customer_type
That case the when customer_type in (1, 2) then id else null end as customer_id
The from tableName

CodePudding user response:

Share the database to add a new column method
  • Related