postgresql 需要添加新的列 ,當customer_type = 1或者2時候 ,添加id 到新列customer_id
原表table大概如下:
id customer_type
111 2
112 1
113 3
114 2
結果如下
id customer_type customer_id
111 2 111
112 1 112
113 3
114 2 114
求助大佬幫寫下sql陳述句
uj5u.com熱心網友回復:
我發現大家寫程式的時候都不喜歡百度,我是不是做了廣告uj5u.com熱心網友回復:
不需要搞什么新列, 創建一個視圖就可以了:create view view_tablename
as
select id
,customer_type
,case when customer_type in (1,2) then id else null end as customer_id
from tableName
uj5u.com熱心網友回復:
各資料庫添加新列的方法分享轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/130259.html
標籤:基礎類
下一篇:萌新求助!
